“too many automatic redirections were attempted” error message when using a httpWebRequest in .NET

流过昼夜 提交于 2019-11-30 11:08:13

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.

Dhivya
loHttp.AllowAutoRedirect = true

Instead of this, you have to use

loHttp.AllowAutoRedirect = False

to avoid error the error

"TOO MANY AUTOMATIC REDIRECTION WERE ATTEMPTED"

I translated the C# that Darryl provided to VB and inserted it before the getResponse call.

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

Maybe, you can individually process for each redirection by catch up Location from response and use suitable cookies.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!