我正在使用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