4

I'm using HTTPClient in my WPF application in order to send a GET message to the server. I know how to extract the content, aka HTML of the page i've been redirected to. Yet i'm unaware of how to get the url of the page i've been redirected to. I've already tried Headers.location, but that header is invalid

Sample code:

private async Task getToken()
{
    using (HttpClient client = new HttpClient())
    using (HttpResponseMessage response = await client.GetAsync(getURL))
    {
        var a = response.Headers.Location;
        using (HttpContent content = response.Content)
        {
            // ...Read the string.
            result = await content.ReadAsStringAsync();
        }
    }
}

The data i need should look like this (GET):

sample result

Tom
  • 95
  • 2
  • 9
  • may be duplicated with this: http://stackoverflow.com/questions/10341475/getting-url-after-a-redirect-using-httpclient-executehttpget – Ivan Yuriev Mar 25 '16 at 14:01
  • @IvanYuriev Actually it's a wee bit of an extension to htat question - in that question it was stated that the location header was in place, and thus url could be acquired. In this case the header is invalid, and i'm looking for a way to get the URL by any other property/whatsoever – Tom Mar 25 '16 at 14:32
  • did you try this: string location = response.Headers.GetValues("Location").FirstOrDefault() – Ivan Yuriev Mar 25 '16 at 14:41
  • @IvanYuriev the thing is that the header "Location" is invalid, and thus = null – Tom Mar 25 '16 at 20:05
  • 1
    its a tricky issue, Tom :) I can't reproduce your situation, so it's hard to help. try, also to use response.RequestMessage.Content.Headers and you may need to read raw request and parse it by yourself - look here for how to do this: http://stackoverflow.com/questions/12045592/view-raw-headers-that-will-be-sent-received-in-httpresponsemessage-httprequest – Ivan Yuriev Mar 25 '16 at 20:25

0 Answers0