码迷,mamicode.com
首页 > 其他好文 > 详细

“重定向次数过多”或者“Too many automatic redirections were attempted”的错误:

时间:2016-07-19 09:33:30      阅读:256      评论:0      收藏:0      [点我收藏+]

标签:

C# 代码

C# code?
1
2
3
4
5
6
7
8
9
String url="http://www.google.com.hk/search?hl=zh-CN&q=孟宪会";
System.Net.HttpWebRequest r = (System.Net.HttpWebRequest)System.Net.HttpWebRequest.Create(url);
r.AllowAutoRedirect = true;
//System.Net.CookieContainer c = new System.Net.CookieContainer();
//r.CookieContainer = c;
System.Net.HttpWebResponse res = r.GetResponse() as System.Net.HttpWebResponse;
System.IO.StreamReader s = new System.IO.StreamReader(res.GetResponseStream(),System.Text.Encoding.GetEncoding("GB2312"));
Response.Write(s.ReadToEnd());
res.Close();



解决方法就是加上CookieContainer,完整的代码:
C# 代码

C# code?

 

1
2
3
4
5
6
7
8
9
String url="http://www.google.com.hk/search?hl=zh-CN&q=孟宪会";
System.Net.HttpWebRequest r = (System.Net.HttpWebRequest)System.Net.HttpWebRequest.Create(url);
r.AllowAutoRedirect = true;
System.Net.CookieContainer c = new System.Net.CookieContainer();
r.CookieContainer = c;
System.Net.HttpWebResponse res = r.GetResponse() as System.Net.HttpWebResponse;
System.IO.StreamReader s = new System.IO.StreamReader(res.GetResponseStream(),System.Text.Encoding.GetEncoding("GB2312"));
Response.Write(s.ReadToEnd());
res.Close();

“重定向次数过多”或者“Too many automatic redirections were attempted”的错误:

标签:

原文地址:http://www.cnblogs.com/lonelyxmas/p/5683298.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!