Skip to content

Instantly share code, notes, and snippets.

@Delaire Delaire/CoreTools.cs
Last active Oct 22, 2019

What would you like to do?
UWP, C# - Retrieve the redirect url using HttpClient from the Headers of the Response - [HttpClient,C#]
public static class CoreTools
public static async Task<string> GetRedirectedUrl(string url)
//this allows you to set the settings so that we can get the redirect url
var handler = new HttpClientHandler()
AllowAutoRedirect = false
string redirectedUrl = null;
using (HttpClient client = new HttpClient(handler))
using (HttpResponseMessage response = await client.GetAsync(url))
using (HttpContent content = response.Content)
// ... Read the response to see if we have the redirected url
if (response.StatusCode == System.Net.HttpStatusCode.Found)
HttpResponseHeaders headers = response.Headers;
if (headers != null && headers.Location != null)
redirectedUrl = headers.Location.AbsoluteUri;
return redirectedUrl;

This comment has been minimized.

Copy link
Owner Author

Delaire commented Mar 22, 2018

I wanted to share a little piece of code that allows you to get the redirect url of an url using HttpClient

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.