当我在特定URL上运行HTTPWebRequest时,它返回503(服务器不可用)。这是我的代码:
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[] firstResponse = webClient.DownloadData(URL);
以下是我在IE中请求页面时发送到浏览器的内容(根据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
我需要在代码中添加其他内容吗?非常感谢。
编辑:这是响应标题:
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
答案 0 :(得分:0)
您的请求可能实际上正在通过。 503响应代码通常表示服务器过载或服务器未正常运行。尝试在同一台计算机上的IE中加载页面,看看是否得到相同的响应。