从网址下载页面 [英] Downloading a page from url

查看:108
本文介绍了从网址下载页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从中下载页面url ang为其创建文件路径?

how to download a page from it url ang create a filepath for it ?

推荐答案

不清楚创建文件路径的含义(请参阅我的对问题发表评论).可能您需要了解什么是下载;您可以随时下载页面;它的下载位置与服务器上的位置无关.

为此,您需要使用类System.Net.HttpWebRequest.请参阅:
http://msdn.microsoft.com/en-us/library/system.net. httpwebrequest.aspx [ ^ ].

由于的实例不是通过调用其构造函数而是通过使用其父类的工厂方法System.Net.WebRequest.Create创建的,因此请参见其说明和代码示例:
http://msdn.microsoft.com/en-us/library/system.net. webrequest.aspx [ ^ ].

这是一些简单的文件下载示例:
http://social.msdn.microsoft.com /Forums/zh-CN/winappswithcsharp/thread/de96a61c-e089-4595-8349-612be5d23ee6/ [ http://code.msdn.microsoft.com/HttpClient-Downloading-to-4cc138fd [ ^ ].

使用HttpWebRequest,您可以控制更多.特别是,您可以继续下载部分下载的文件.如果部分下载了文件,但由于某种原因取消了下载,则可以使用已下载的部分从取消的位置开始.您可以在前一段时间为CodeProject用户提供的应用程序中找到我的代码:
如何从Internet下载文件 [ ^ ].

—SA
Not clear what you mean by creating of a file path (please see my comment to the question). Probably you need to understand what a download is; you download a page whenever you want; it''s downloaded location have nothing do to with the location on the server.

To do it, you need to use the class System.Net.HttpWebRequest. Please see:
http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest.aspx[^].

As the instance of is created not by calling its constructor but using its parent class''s factory method System.Net.WebRequest.Create, please see its description and the code sample:
http://msdn.microsoft.com/en-us/library/system.net.webrequest.aspx[^].

This is some simple sample for file download:
http://social.msdn.microsoft.com/Forums/en-US/winappswithcsharp/thread/de96a61c-e089-4595-8349-612be5d23ee6/[^].

The alternative, simplified method is the one using the class System.Net.Http.HttpClient:
http://code.msdn.microsoft.com/HttpClient-Downloading-to-4cc138fd[^].

With HttpWebRequest, you have more control. In particular, you can continue downloaded partially downloaded file. When a file was partially downloaded, but the downloading was cancelled by whatever reason, you can start with the place of the cancellation, using already downloaded part. You can find my code in my application I provided for CodeProject users a while ago:
how to download a file from internet[^].

—SA


这篇关于从网址下载页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆