Skip to content

Instantly share code, notes, and snippets.

@tobbez
Created March 8, 2010 02:38
Show Gist options
  • Save tobbez/324792 to your computer and use it in GitHub Desktop.
Save tobbez/324792 to your computer and use it in GitHub Desktop.
Getting the target of an HTTP redirect in C#
string GetRedirectTarget(string url)
{
System.Net.HttpWebRequest request = (System.Net.HttpWebRequest)WebRequest.Create(url);
request.AllowAutoRedirect = false;
System.Net.HttpWebResponse response = (System.Net.HttpWebResponse)request.GetResponse();
return response.Headers.Get("Location");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment