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

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

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()
有帮助吗?

解决方案

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

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

你可能不保存cookie和重定向循环被抓到。

其他提示

loHttp.AllowAutoRedirect = true

取而代之的是,你必须使用

loHttp.AllowAutoRedirect = False

,以避免错误的错误

  

“TOO MANY自动重定向已尝试”

我编译该达里尔提供给VB的C#和GETRESPONSE呼叫之前插入它。

Dim cookieContainer As CookieContainer = New CookieContainer()
loHttp.CookieContainer = cookieContainer
loWebResponse = loHttp.GetResponse()

也许,可以分别通过从响应赶上位置,并使用合适的饼干每个重定向过程。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top