Member-only story
Debugging HTTP Requests in .Net Core
Intercept requests and generate a curl command automatically

When receiving errors resulting from HTTP requests of Web APIs is very common to start investigating the issue by extracting the exact request that the app is doing and preparing a curl command or a postman call to reproduce the issue.
POST UPDATE
If you are here just because you are looking for an easy way to log your HTTP calls, you can use this NuGet package I created in this post.
But If you are here to understand better how it does work, that’s even better, enjoy it.
If you’re not a Medium paid member, you can read this story for free using the following link
This is not a complex task, but it consumes a lot of time since we need to run our apps identify the request, inspect the address, parameters, headers, keys and etc, copy it to a file, and build the curl command.
Some people even spend some time, installing sniffer apps like Fiddler, and Wireshark to inspect all the HTTP traffic from the computer, or even serializing the requests and log it into text files, those approaches certainly help to solve the problems but it requires installing additional apps or writing custom log routines many times.
In this article, I will show how to use HTTP Message Handlers to intercept HTTP requests and automatically generate curl commands for your requests in a very easy and quick way.
Wait, no custom code is needed to do that
If you are thinking about the native HTTP log handlers in Asp.Net 6.0, you are absolutely right, we do not need custom code.
If you are using Asp.Net 6.0, check the documentation here and log all your requests even easier than the techniques presented and this article
But, If you are using older versions such as 5.0 or 3.1 (or older) maybe this article can be helpful for you.
Another reason to keep reading is to understand how we can take advantage of the custom message handlers, not only for log purposes but also for any other needs (as mentioned later in this article)