httpwebrequest请求失败

x245322856 2014-10-27 10:03:42
private void button1_Click(object sender, EventArgs e)
{
string url = "";
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream stream = response.GetResponseStream();
StreamReader sr = new StreamReader(stream, Encoding.UTF8);
richTextBox1.Text = sr.ReadToEnd();
}


url是请求的网址。对于常见的网站如百度等,这段代码可以请求网页源码。
而对于这个网址:http://waimai.meituan.com/restaurant/28240
却请求失败,显示错误,远程服务器返回错误(429)
...全文
208 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
x245322856 2014-10-27
  • 打赏
  • 举报
回复
那要怎么办,我还想写一个刷信誉的程序呢
全栈极简 2014-10-27
  • 打赏
  • 举报
回复
服务器做了限制了,我刚刚测试了一下是可以返回的,现在确实跟你一样不行了。
蒋晟 2014-10-27
  • 打赏
  • 举报
回复
自己查一下就知道 HTTP Status Code 429 = Too Many Requests 服务器发现你在刷
x245322856 2014-10-27
  • 打赏
  • 举报
回复
不行,跟没加一样,而且我抓过包。没有cookie
全栈极简 2014-10-27
  • 打赏
  • 举报
回复
string url = "http://waimai.meituan.com/restaurant/28240"; HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); System.Net.CookieContainer cc = new System.Net.CookieContainer(); request.CookieContainer = cc; HttpWebResponse response = (HttpWebResponse)request.GetResponse(); Stream stream = response.GetResponseStream(); StreamReader sr = new StreamReader(stream, Encoding.UTF8); richTextBox1.Text = sr.ReadToEnd();

110,571

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧