Tôi đang sử dụng HttpWebRequest và tôi gặp lỗi khi thực hiện GetResponse().Lỗi HttpWebRequest: 503 máy chủ không khả dụng
tôi sử dụng mã này:
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;
}
Em bắt được lỗi tương tự khi yêu cầu URL trong một trình duyệt hoặc một công cụ như curl? – jlafay
Điều đó có vẻ giống như một URL rất lạ để tìm nạp theo chương trình. Có lý do gì không? –
http://www.google.com/sorry/ trả về 503. Nếu bạn đang cố gắng tự động hóa một số lượng lớn truy vấn tới Google, bạn có thể nhận được URL đó. Nhưng như Jon Skeet đã hỏi, tại sao bạn gửi yêu cầu tới URL đó ngay từ đầu? Xem http://support.google.com/websearch/bin/answer.py?hl=vi&answer=86640 –