Is there anything like this from Java: HTTPClient - Capture a list of all Redirects
for C# HttpClient?
Is there anything like this from Java: HTTPClient - Capture a list of all Redirects
for C# HttpClient?
You can do this using HttpWebRequest:
public static string GetRedirectedUrls(string url)
{
StringBuilder sb = new StringBuilder();
while (!string.IsNullOrWhiteSpace(url))
{
sb.AppendLine(url);
HttpWebRequest request = HttpWebRequest.CreateHttp(url);
request.AllowAutoRedirect = false;
using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
{
url = response.GetResponseHeader("Location");
}
}
return sb.ToString();
}