'How to get HttpRequestMessage/HttpClient request details before sending it to the OpenAPI RESTful service in .NET

We have the feature where execute OpenAPI restful service by interrogate class and methods.

In order to check what is wrong, the customer needs the request I'm sending. Similarly to get response details from HttpResponseMessage

As part of the OpenAPI restful service execution, I have implemented below partial methods where I can have all the required details in below two partial methods.

        public static void ProcessResponse(System.Net.Http.HttpClient client, System.Net.Http.HttpResponseMessage response)
    {
        if (client != null && response != null)
        {
        }
    }

    
    public static void PrepareRequest(System.Net.Http.HttpClient client, System.Net.Http.HttpRequestMessage request, string url)
    {
        if (client != null && request != null)
        {
            request.Headers.Accept.Remove(new MediaTypeWithQualityHeaderValue("application/xml"));
            request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
        }
    }

But I'm not sure How do I get data in these methods to show in the UI when executing?

Any help greatly appreciated.

Regards, Amar



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source