0

Hi Want to log http Request before making the call. With all the values - for dev purposes. My code is below

   using (HttpClient hc = httpClient)
            {

                    hc.BaseAddress = new Uri(endpoint); 
                    hc.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

**// Want to Log the request here that captures Header and body content**

                    HttpResponseMessage response = hc.PostAsJsonAsync(url, bodyKeyValues).Result;

            }

I am not to able to figure out how to get the HttpRequestobject. Is there a way to get the httpRequestObject as a whole?

Night Monger
  • 770
  • 1
  • 10
  • 33
  • 1
    Well, what is keeping you from doing it? – Peter Bons Jul 06 '17 at 16:50
  • @PeterBons I am not sure how to get the httprequestmessage from httpclient. I generally log the responses as console.writeline(response.ReadAsStringAsync().Result) - but i am not sure how to get the whole request. – Night Monger Jul 06 '17 at 16:54
  • 1
    @NightMonger, Create a delegate handler and inject that into the hander to intercept the request before it is sent. You can do your logging there – Nkosi Jul 06 '17 at 17:07
  • There is built-in logging/tracing E.g. https://stackoverflow.com/questions/3808016/how-do-i-see-the-raw-http-request-that-the-httpwebrequest-class-sends / https://stackoverflow.com/questions/18924996/logging-request-response-messages-when-using-httpclient – Alex K. Jul 06 '17 at 17:11

0 Answers0