How to get last url from HttpClient?

前端 未结 1 1214
北恋
北恋 2021-02-05 05:59

OK, i was recently switch to .NET framework 4.5 and start using HttpClient instead of HttpWebRequest & Response. I really love that async/await style but i don\'t know how t

1条回答
  •  孤街浪徒
    2021-02-05 06:16

    So from the msdn articles HttpResponseMessage returns as a Task from an HttpClient call.

    This HttpResponseMessage has a property called Request Message, which has a property called RequestUri, make sure to look in the properties section of this link.

    Sample Code:

    // Create a New HttpClient object.
    HttpClient client = new HttpClient();
    HttpResponseMessage response = await client.GetAsync("http://www.yahoo.com/");
    response.EnsureSuccessStatusCode();
    string responseUri = response.RequestMessage.RequestUri.ToString();
    Console.Out.WriteLine(responseUri);
    

    0 讨论(0)
提交回复
热议问题