I'm trying to retrieve a list of urls that represent the path taken from URL X
to URL Y
where X
may be redirected several times.
For example:
http://www.example.com/foo
That will redirect to:
http://www.example.com/bar
Which then redirects to:
http://www.example.com/foobar
Is there a way of get this redirect pathway from the response object as a string: http://www.example.com/foo > http://www.example.com/bar > http://www.example.com/foobar
I'm able to get at the final URL via ResponseUri
e.g.
public static string GetRedirectPath(string url)
{
StringBuilder sb = new StringBuilder();
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
using (var response = (HttpWebResponse)request.GetResponse())
{
sb.Append(response.ResponseUri);
}
return sb.ToString();
}
But this obviously skips the URL in between. There doesn't seem be an easy way (or way at all?) to get the full pathway?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…