0

How can i make the following post request in c#

fetch("http://172.16.1.1:8090/login.xml", {
  "headers": {
    "accept": "*/*",
    "accept-language": "en-US,en;q=0.9",
    "content-type": "application/x-www-form-urlencoded"
  },
  "referrer": "http://172.16.1.1:8090/httpclient.html",
  "referrerPolicy": "strict-origin-when-cross-origin",
  "body": "mode=191&username=21011012&password=4321&a=1668601840902&producttype=0",
  "method": "POST",
  "mode": "cors",
  "credentials": "omit"
});

i want to mimic this post request in c#

jps
  • 20,041
  • 15
  • 75
  • 79

1 Answers1

0

I recommended HttpClient(asynchronous and high performance). You can try this.

Add NameSpace

      using System.Net.Http;

Code for Post in Method

       private static readonly HttpClient client = new HttpClient();

        var values = new Dictionary<string, string>
        {
            { "mode", "191" },
            { "username", "21011012" },
            { "password", "world" }
            { "a", "1668601840902" },
            { "producttype", "0" }
        };

        var content = new FormUrlEncodedContent(values);

        var response = await client.PostAsync("yoururl", content);

        var responseString = await response.Content.ReadAsStringAsync();
Pradeep Kumar
  • 1,193
  • 1
  • 9
  • 21