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

后端 未结 4 1529
不思量自难忘°
不思量自难忘° 2021-01-01 14:52

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 req

相关标签:
4条回答
  • 2021-01-01 15:31

    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()
    
    0 讨论(0)
  • 2021-01-01 15:38
    loHttp.AllowAutoRedirect = true
    

    Instead of this, you have to use

    loHttp.AllowAutoRedirect = False
    

    to avoid error the error

    "TOO MANY AUTOMATIC REDIRECTION WERE ATTEMPTED"

    0 讨论(0)
  • 2021-01-01 15:40

    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.

    0 讨论(0)
  • 2021-01-01 15:42

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

    0 讨论(0)
提交回复
热议问题