C # httpclient PostAsJson sending a GET request instead of POST

I am using HttpClient to create a submit request. I return the 405 method is not allowed. When you capture a trace in a violinist, it exits as GET instead of POST!

using (var client = new HttpClient())
            {
                var url = AppSettingsUtil.GetString("url");
                var response = client.PostAsJsonAsync(url, transaction).Result;
            }

I am aware of async / wait issues. This is a simplified selection to show the problem.

Are there any web.config or machine.config settings that might affect this? Other requests (sent via RestSharp) send messages correctly

This is what the violinist captures. Repeating the trace in the violin also returns 405 (as expected). Manually switch it to POST and start work from a violinist.

Also, perhaps because the method was switched to GET, there is no body in fiddler, I had to manually insert JSON

GET /*URL*/ HTTP/1.1
Content-Type: application/json; charset=utf-8
Host: /*host*/
Connection: Keep-Alive
+4
1

, - URL-, , . HttpClient , Get.

​​HttpClient , , , , , .

+2

Source: https://habr.com/ru/post/1626592/


All Articles