Httpwebrequest / Httpwebresponse - number of redirects

I am trying to find out how many times my web request was redirected before I finally landed in the final content.

I create my web request as follows:

var httpRequest = (HttpWebRequest) WebRequest.Create("some arb path");
httpRequest.AllowAutoRedirect = followRedirects; 

I looked at the following URL http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest.maximumautomaticredirections.aspx

However, I do not want to impose a restriction. I really want him to keep track of all redirects (not wanting links to all URLs), but simply, for example, says "You have been redirected X times."

I hope there is a quick way to do this, as I currently assume that I will need to capture all 3xx codes and create a new request for each (hope not!).

+3
source share
1 answer

It is impossible to achieve what you want. You will need to grab every 3xx request and issue a new one with a redirect location header.

However, if you want to use your own C / C ++ code and write directly to WININET (which is the library used by IE), it will give you (via a callback mechanism) a notification for each redirect that has occurred.

+1
source

Source: https://habr.com/ru/post/1757976/


All Articles