小编don*_*s90的帖子

C#下载未知格式的图像

我正在处理批量下载程序,但有些URL没有正确发送数据.

例如,此页面:http://i.imgbox.com/absMQK6A.png

在任何互联网浏览器中,此页面显示图像,但在我的程序中,下载奇怪的数据.我认为这个URL是假的或受保护的(我不太了解HTML.)

顺便说一句,在IE中,我可以通过右键单击正常下载该图像并保存为图像.所以我想在我的程序中模仿这种行为.

我怎样才能做到这一点?

以下是我的程序代码的一部分.

HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(DownloadAddress);
if (Proxy != null)
{
    request.Proxy = Proxy;
}
if (!string.IsNullOrWhiteSpace(UserAgent))
{
    request.UserAgent = UserAgent;
}

HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream downloadHttpStream = response.GetResponseStream();
int read = downloadHttpStream.Read(buffer, 0, buffer.Length);
// output codes
Run Code Online (Sandbox Code Playgroud)

UserAgent是具有浏览器信息的字符串.如IE,Firefox等

谢谢.

html c# http

5
推荐指数
1
解决办法
715
查看次数

标签 统计

c# ×1

html ×1

http ×1