c#应用程序通过代理读取图像

时间:2014-11-29 15:29:07

标签: c# .net

我创建了一个程序来创建https图像请求。

我的程序已成功读取图像。 这是我的代码的一部分:

request = (HttpWebRequest)WebRequest.Create(" Image URL ");
request.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:31.0) Gecko/20100101 Firefox/31.0";
request.Accept = "image/png,image/*;q=0.8,*/*;q=0.5";
request.Headers.Set(HttpRequestHeader.AcceptLanguage, "en-US,en;q=0.5");
request.Headers.Set(HttpRequestHeader.AcceptEncoding, "gzip, deflate");

request.KeepAlive = true;

response = (HttpWebResponse)request.GetResponse();

using (var stream = response.GetResponseStream())
{
    pictureBox1.Image = Bitmap.FromStream(stream);
}
response.Close();

然后我尝试通过fiddler远程代理发送图像请求,但失败了。 抛出以下异常:

System.ArgumentException: Parameter is not valid.
   at System.Drawing.Image.FromStream(Stream stream, Boolean useEmbeddedColorManagement, Boolean validateImageData)
   at System.Drawing.Image.FromStream(Stream stream)
   at ..

我的代码出了什么问题?

0 个答案:

没有答案