"太多的自动重定向已尝试"使用.NET中的HttpWebRequest时错误信息 [英] "too many automatic redirections were attempted" error message when using a httpWebRequest in .NET

查看:224
本文介绍了"太多的自动重定向已尝试"使用.NET中的HttpWebRequest时错误信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在尝试使用WebRequest类在vb.net要求,如http://www.google.com/?q=random的页面。 我们是一个防火墙的后面,所以我们要验证我们的要求。 我已经加入我的凭据得到过去的认证的一部分。 但一旦工作似乎进入一个重定向循环。

有没有人有一个想法,意见,suggetions这是为什么? 有没有其他人遇到这个问题?

 昏暗loHttp由于HttpWebRequest的= CTYPE(WebRequest.Create(_url),HttpWebRequest的)
loHttp.Timeout = 10000
loHttp.Method =GET
loHttp.KeepAlive = TRUE
loHttp.AllowAutoRedirect = TRUE
loHttp。preAuthenticate = TRUE
昏暗_cred1作为的NetworkCredential = ... //这是设置
//剪断了这个东西
loHttp.Credentials = _cc
loWebResponse = loHttp.GetResponse()
 

解决方案

请确保您有一个cookie的容器设置。

 的CookieContainer的CookieContainer =新的CookieContainer();
loHttp.CookieContainer =的CookieContainer;
 

你可能不保存Cookie和陷入在一个重定向循环。

I am attempting to request a page like "http://www.google.com/?q=random" using the webrequest class in vb.net. we are behind a firewall, so we have to authenticate our requests. I have gotten past the authentication part by adding my credentials. But once that works it seems to go into a redirecting loop.

Does anyone have an ideas, comments, suggetions why this is? Has anyone else experienced this problem?

Dim loHttp As HttpWebRequest =  CType(WebRequest.Create(_url), HttpWebRequest)
loHttp.Timeout = 10000
loHttp.Method = "GET"
loHttp.KeepAlive = True
loHttp.AllowAutoRedirect = True
loHttp.PreAuthenticate = True
Dim _cred1 As NetworkCredential = ... //this is setup
//snip out this stuff
loHttp.Credentials = _cc
loWebResponse = loHttp.GetResponse()

解决方案

Make sure you have a cookie container setup.

CookieContainer cookieContainer = new CookieContainer();
loHttp.CookieContainer = cookieContainer;

You are probably not saving cookies and getting caught in a redirect loop.

这篇关于"太多的自动重定向已尝试"使用.NET中的HttpWebRequest时错误信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆