开发者

C# Web Request / Server Unavailable Error / HTTP Headers

When I run a HTTPWebRequest on a particular URL, it returns 503 (Server Unavailable). Here is my code:

        webClient.Headers[HttpRequestHeader.UserAgent] = _userAgent;
        webClient.Headers[HttpRequestHeader.AcceptEncoding] = "gzip, deflate";
        webClient.Headers[HttpRequestHeader.Accept] = "Accept: application/x-ms-application, image/jpeg, application/xaml+xml, image/gif, image/pjpeg, application/x-ms-xbap, */*";
        webClient.Headers[HttpRequestHeader.Cookie] = "searchState=WA";

        byte[] firstRespons开发者_Go百科e = webClient.DownloadData(URL);

Here is what is sent to the browser when I request the page in IE (according to Fiddler):

GET http://www.[url].com/[url] HTTP/1.1
Accept: application/x-ms-application, image/jpeg, application/xaml+xml, image/gif, image/pjpeg, application/x-ms-xbap, */*
Accept-Language: en-US
User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; Media Center PC 6.0; .NET4.0C; .NET CLR 3.5.30729; .NET CLR 3.0.30729; .NET4.0E)
Accept-Encoding: gzip, deflate
Proxy-Connection: Keep-Alive
Host: www.[url].com
Cookie: searchState=WA

Is there anything else I need to add to my code? Many thanks.

EDIT: here are the response headers:

HTTP/1.0 200 OK
Date: Fri, 21 Jan 2011 04:02:33 GMT
Server: Apache-Coyote/1.1
Cache-Control: no-cache
Pragma: no-cache
Expires: Thu, 01 Jan 1970 00:00:00 GMT
Content-Type: text/html;charset=UTF-8
Set-Cookie: JSESSIONID=39EFAAA14B9C6E0384631007966B7CB8; Path=/
Set-Cookie: searchState=WA; Expires=Sun, 20-Feb-2011 04:02:33 GMT; Path=/
Set-Cookie: search_tab=R; Path=/
X-Cache: MISS from 200.157.247.7
Proxy-Connection: close
Content-Length: 26987


It's likely your request is actually getting through. A 503 response code typically means the server's overloaded or a piece of the server is not running properly. Try loading the page in IE on the same machine and see if you get the same response.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜