从httprequest获取图像并不起作用

时间:2014-08-19 23:16:10

标签: c# image httprequest httpresponse recaptcha

我有以下Image,当使用任何浏览器打开此图片时,无论是普通还是私人模式,它都能正常运行。

enter image description here

但使用HttpRequest& HttpResponse它产生以下内容:

enter image description here

这是我的代码:

    /// <summary>
    /// 
    /// </summary>
    /// <param name="imageUrl"></param>
    /// <returns></returns>
    private static Image GetImage(string imageUrl)
    {
        HttpWebRequest request = (HttpWebRequest)WebRequest.Create(imageUrl);
        request.Method = "GET";
        request.KeepAlive = true;
        request.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8";
        request.Host = "www.google.com";
        request.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/32.0.1700.107 Safari/537.36";
        HttpWebResponse response = (HttpWebResponse)request.GetResponse();

        return Image.FromStream(response.GetResponseStream());
    }

这是来自Fiddler的Raw HttpRequest:

    GET https://www.google.com/recaptcha/api/image?c=03AHJ_VusG9FppmdZqKUPjxoVUV4290vtoCQDM8jw9BROEI396sx7J4YYxUBab1zEQg2T94n19CiW2ahGLAtGm5H7nEgckTtJACFcXGZg_frhYIsBAg8VaY5JAbP4oJCx3cmknqltFsYeDUrdv0ZWbFjcMtYuZ0FQnh3blc5ZEx1oJuWJpLzPy0WhhZUIgJ_EXpiC5w-pvt00P HTTP/1.1
Host: www.google.com
Connection: keep-alive
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/32.0.1700.107 Safari/537.36
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-US,en;q=0.8,ar;q=0.6

任何人都可以帮助您成功获取此图像。感谢。

0 个答案:

没有答案