我正在使用HttpWebRequest,并且在执行GetResponse()时出现错误。HttpWebRequest错误:503服务器不可用
我使用此代码:
private void button1_Click(object sender, EventArgs e)
{
Uri myUri = new Uri("http://www.google.com/sorry/?continue=http://www.google.com/search%3Fq%3Dyamaha");
// Create a 'HttpWebRequest' object for the specified url.
HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create(myUri);
// Set the user agent as if we were a web browser
myHttpWebRequest.UserAgent = @"Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.4) Gecko/20060508 Firefox/1.5.0.4";
HttpWebResponse myHttpWebResponse = (HttpWebResponse)myHttpWebRequest.GetResponse();
var stream = myHttpWebResponse.GetResponseStream();
var reader = new StreamReader(stream);
var html = reader.ReadToEnd();
// Release resources of response object.
myHttpWebResponse.Close();
textBox1.Text = html;
}
你得到同样的错误,要求在浏览器的URL或像curl这样的工具是什么时候? – jlafay 2012-04-11 13:51:57
这看起来像一个绝对奇怪的URL以编程方式获取。任何理由吗? – 2012-04-11 13:52:04
http://www.google.com/sorry/返回503.如果您尝试自动化大量的Google查询,则可能会获得该网址。但正如Jon Skeet所问,为什么你首先向这个URL提交请求?请参阅http://support.google.com/websearch/bin/answer.py?hl=zh-CN&answer=86640 – 2012-04-11 13:53:16