Search code examples
c#posthttpwebrequest

How to send data in a POST request with HttpWebRequest


In my post request I need to send data as follows:

{
   "LoginData":{
      "name": "xyz",
      "password": "pw"
   }
}

I have not seen an example of such a header (two levels json)


Solution

  • You can use HttpClient to achieve this. where you have to create C# class of your json format, you can do it from here. and then serialize your c# object using newtonsoft.json and then use PostAsync method of HttpClient.