使用httprequest下载文件 [英] Downloading files using httprequest

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

问题描述

是否可以使用httprequest从网站下载文件?我只习惯使用它来获取页面的源代码。如果没有办法使用httprequest,有没有办法使用C#下载文件,而不必使用webbrowser?

Is it possible to download files from a website using httprequest? I am only used to using it to get source code of a page. If there is no way to do it using httprequest, is there a way to download files using C# without having to use the webbrowser?

编辑:答案必须允许我选择文件下载到硬盘上的位置

The answer must allow me to chose the location on the hard drive where the file will be downloaded to

推荐答案

您可以绝对使用 HttpRequest 通过获取 WebResponse 并使用其响应流。或者,使用 WebClient ,其 DownloadFile DownloadData 方法,使生活更轻松。

You can absolutely use HttpRequest by getting the WebResponse and using its response stream. Alternatively, use WebClient, with its DownloadFile and DownloadData methods to make life easier.

最终没有太大的区别,请求得到作为响应的二进制文件和作为响应获得一些HTML的请求。在某些方面,二进制响应更容易处理,因为您不需要担心字符编码。

Ultimately there's not much difference between a request which gets a binary file as a response and a request which gets some HTML as a response. In some ways a binary response is easier to deal with, as you don't need to worry about character encodings.

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

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