网站尝试自动重定向的次数太多是什么意思?怎样解决?
我做了个网站,用站长工具测试收录情况时,百度新闻显示“尝试自动重定向的次数太多”是什么意思?怎样解决?...
我做了个网站,用站长工具测试收录情况时,百度新闻显示“尝试自动重定向的次数太多”是什么意思?怎样解决?
展开
1个回答
展开全部
private string GetHTML(string url, string cookie)
{
if (String.IsNullOrEmpty(url))
{
return null;
}
else
{
try
{
url = url.Replace(" ", "%20");
url = url.Replace("&", "&");
}
catch
{
}
}
string html = null;
string curCookie = null;
HttpWebRequest myRequest = null;
HttpWebResponse myResp = null;
StreamReader myReader = null;
for (int i = 0; i < 3; i++)
{
try
{
myRequest = (HttpWebRequest)WebRequest.Create(url);
myRequest.AllowAutoRedirect = false;
myRequest.Timeout = 60 * 1000;
myRequest.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)";
myRequest.Headers.Add("Cookie", cookie);
myRequest.KeepAlive = true;
myResp = (HttpWebResponse)myRequest.GetResponse();
curCookie = myResp.Headers["Set-Cookie"];
curCookie = curCookie.Substring(0, curCookie.IndexOf(";"));
myReader = new StreamReader(myResp.GetResponseStream(), Encoding.Default, true);
html = myReader.ReadToEnd();
}
catch (Exception e)
{
// Console.WriteLine(e.ToString());
continue;
}
finally
{
if (myReader != null)
{
myReader.Close();
}
if (myResp != null)
{
myResp.Close();
}
}
if (html == null)
{
continue;
}
else if (html.IndexOf("Object moved") > 0) //手动获取转向地址,再次获取html代码
{
int pos1 = html.IndexOf("http://");
int pos2 = html.IndexOf("\">");
url = html.Substring(pos1, pos2 - pos1);
html = GetHTML(url, curCookie);
}
break;
}
return html;
}
{
if (String.IsNullOrEmpty(url))
{
return null;
}
else
{
try
{
url = url.Replace(" ", "%20");
url = url.Replace("&", "&");
}
catch
{
}
}
string html = null;
string curCookie = null;
HttpWebRequest myRequest = null;
HttpWebResponse myResp = null;
StreamReader myReader = null;
for (int i = 0; i < 3; i++)
{
try
{
myRequest = (HttpWebRequest)WebRequest.Create(url);
myRequest.AllowAutoRedirect = false;
myRequest.Timeout = 60 * 1000;
myRequest.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)";
myRequest.Headers.Add("Cookie", cookie);
myRequest.KeepAlive = true;
myResp = (HttpWebResponse)myRequest.GetResponse();
curCookie = myResp.Headers["Set-Cookie"];
curCookie = curCookie.Substring(0, curCookie.IndexOf(";"));
myReader = new StreamReader(myResp.GetResponseStream(), Encoding.Default, true);
html = myReader.ReadToEnd();
}
catch (Exception e)
{
// Console.WriteLine(e.ToString());
continue;
}
finally
{
if (myReader != null)
{
myReader.Close();
}
if (myResp != null)
{
myResp.Close();
}
}
if (html == null)
{
continue;
}
else if (html.IndexOf("Object moved") > 0) //手动获取转向地址,再次获取html代码
{
int pos1 = html.IndexOf("http://");
int pos2 = html.IndexOf("\">");
url = html.Substring(pos1, pos2 - pos1);
html = GetHTML(url, curCookie);
}
break;
}
return html;
}
追问
尊敬的x9658xc:您好。我是菜鸟,不懂你那些代码说的是什么意思,请详细一点,不胜感激。
追答
查询次数太多,你可以过一会再查也可以去以下网址
http:// ————————此线无用————————————
topic.csdn. ——————————此线无用————————————
net/u/20071030/————————此线无用——————————————
15/b d4201 ——————————此线无用————————————————
e7-22d8-4c
23-92e3-5c57b
9f9fd02.htm解决办发见以上网址 网址自己连一下
参考资料: CSDN论谈
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询