none
base address + relative address in HttpClient... what is full address? RRS feed

  • Question

  • Hello,

    I have an HttpClient that's sending off a request like this:

                string APIBaseAddress = ConfigurationManager.AppSettings["APIBaseAddress"];
                string APIRelativeAddress = ConfigurationManager.AppSettings["APIRelativeAddress"];
    
                var client = new HttpClient();
                client.BaseAddress = new Uri(APIBaseAddress);
    
    ...
    
    	var securityTokenRequest = new HttpRequestMessage(HttpMethod.Post, $"{APIRelativeAddress}/token");
    
    ...
    
    client.SendAsync(securityTokenRequest);



    It takes APIBaseAddress as the base address and {APIRelativeAddress}/token as the specific address relative to the base address.

    What I'm wondering is: what does the full address end up looking like? Is it just APIBaseAddress/{APIRelativeAddress}/token?

    Is there any way to check the HttpClient object to see what the full object is?
    Wednesday, April 4, 2018 8:22 PM

All replies

  • Hello gib898,

    >>What I'm wondering is: what does the full address end up looking like? Is there any way to check the HttpClient object to see what the full object is

    When I want to see http request header I usually use third party tools to capture http request. it will provide entire request message for me to debug. you could try to use fidder or others.

    Best Regards,

    Neil Hu


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, April 5, 2018 6:49 AM
    Moderator
  • HttpClient simply combines the base address with the URL provided in the call (taking the slash into account).

    var client = new HttpClient();
    client.BaseAddress = "http://tempuri.org";
    
    //http://tempuri.org/myresource
    client.GetStringAsync("myresource");
    HttpClient supports detailed logging of request/responses but that would turn it on for all requests. Instead you might consider using an HTTP handler that logs the calls. There is one available via NuGet if you're interested.


    Michael Taylor http://www.michaeltaylorp3.net

    Friday, April 6, 2018 2:49 PM
    Moderator