I have request written in JavaScript, which works fine
fetch(someUrl, {
"headers": { someHeader1, someHeader2, /* and so on... */ },
"body": someBody,
"method": "POST"
});
I also have exactly same request written in C#, which doesnt work at all
HttpClient client = new HttpClient();
client.DefaultRequestHeaders.Add(someHeader1);
client.DefaultRequestHeaders.Add(someHeader2); // and so on...
var content = new StringContent(someBody);
var response = await client.PostAsync(someUrl, content);
Now I need to find out the bug in C# code in order to fix it. How can I convert these two code snippet to same representation, to be able to see, what is the difference between them?
As I am not able to mark both question and comment as two correct answers, that helped to resolve my problem, I will rewrite necessery info into single post.
As Charlieface suggests, tool like Fiddler can record outgoing packets and show them in structured and easy-to-orient way.
After inspecting packets details, we will find out, that .DefaultRequestHeader() method silently ignores our attempts to set url encoded header.
As Lee Dungx suggest, we have to use FormUrlEncoded object to correctly set abovementioned header, after which our program starts to work.