WebClient Does not automatically redirect

Try adding

request.AllowAutoRedirect = true;

right under the

var request = base.GetWebRequest(address);

It solved some similar problems for me, even though AllowAutoRedirect is supposed to be true by default.


That shouldn't be surprising, given that HttpWebRequest is not a browser. If you need to perform these redirects, then check the HttpWebResponse.StatusCode, and make another request if it's a redirect code in the 300's. Note from the link under 10.3 Redirection 3xx:

This class of status code indicates that further action needs to be taken by the user agent in order to fulfill the request. The action required MAY be carried out by the user agent without interaction with the user if and only if the method used in the second request is GET or HEAD. A client SHOULD detect infinite redirection loops, since such loops generate network traffic for each redirection.


Comments

  1. Conor

    • 2015/5/8

    Try adding request.AllowAutoRedirect = true;. right under the var request = base.GetWebRequest(address);. It solved some similar problems 

  2. Maxim

    • 2017/8/5

    WebClient Does not automatically redirect. When logging the login process using Firebug i see that it is like this. When making a post request using my code below it did not make the automatic GET requests that the browsers is doing. using System; using System.Net; namespace Test { class HttpHandler : WebClient { private CookieContainer

  3. Colin

    • 2020/9/19

    WebClient Does not automatically redirect. Solution: Try adding request.AllowAutoRedirect = true;. right under the var request = base.GetWebRequest(address);.

  4. Martinez

    • 2016/12/30

    You cannot override having automatic redirection dis-allowing HTTPS -> HTTP. However, you can set automatic redirection to false. var httpClient = new HttpClient ( new HttpClientHandler { AllowAutoRedirect = false , });

  5. Brooks

    • 2016/10/21

    class MyWebClient : WebClient { Uri _responseUri; public Uri ResponseUri { get with a status code between 300-399 will not be automatically redirected.

  6. Scott

    • 2015/7/15

    WebClient - detect response redirect. based on the command line options. In most cases, I can trap the 404. URL or it's offline for whatever reason. The problem I'm running into. the 404 condition and redirects the request to another page.

  7. Adam

    • 2017/11/1

    Hi, I am using the below code to Login and redirect the another domain site. Unfortunately it is not redirecting instead it is giving the 

  8. Bentley

    • 2018/5/24

    true if the request should automatically follow redirection responses from the Internet resource; otherwise, false. The default value is true. Examples. The following code example uses the AllowAutoRedirect property to allow the request to follow redirection responses. // Create a new HttpWebRequest Object to the mentioned URL.

  9. Cason

    • 2019/10/26

    Unlike its brother HttpWebRequest, the WebClient class automatically follows Redirects are very common in all kinds of websites as they allow the owner 

  10. Maximus

    • 2018/6/26

    Make The WebClient Class follow redirects and get Target Url. Unlike its brother HttpWebRequest, the WebClient class automatically follows redirects, but if you need to get the "final" url, you'll need to "wrap" your WebClient in a class that derives from System.Net.WebClient. Here's an example: using System; using System.Net;

  11. Edison

    • 2018/4/8

    I'm experimenting with WebClient and want it to return the initial response and not issue a subsequent request.

  12. Kabir

    • 2015/2/26

    Ensure that “Do not allow client printer redirection” is set to “Not configured” or “Disabled“. Another setting you may want to check is the “Redirect only the default client printer“.

  13. Francisco

    • 2020/7/29

    The standard C# WebClient is not always sufficient. The extra features include: /// ability to disable automatic redirect handling, 

  14. Simeon

    • 2019/7/18

    Remarks. Set AllowAutoRedirect to true if you want the handler to automatically follow HTTP redirection headers to the new location of the resource. The maximum number of redirections to follow is set by the MaxAutomaticRedirections property. If AllowAutoRedirect is set to false, all HTTP responses with an HTTP status code from 300 to 399 are

  15. Morales

    • 2016/12/7

    You are then redirected to the default auto-generated login page, For example, the authorization-uri , token-uri , and user-info-uri do not change often 

  16. Leonidas

    • 2016/4/3

    You can use the Secure Login Web Client to launch an SAP GUI connection using a configuration that, for example, does not use a local saplogon.ini 

Comments are closed.

Recent Posts