I want to send json data in POST request using C#.
I have tried few ways but facing lot of issues . I need to request using request body as raw json from string and json data from json file.
How can i send request using these two data forms.
Ex: For authentication request body in json --> {"Username":"myusername","Password":"pass"}
For other APIs request body should retrieved from external json file.
You can use the
HttpClient
instead of theWebClient
andHttpWebRequest
. It's a newer implementation.When you need your
HttpClient
more then once it's recommended to only create one instance and reuse it or use the newHttpClientFactory
.You can use either
HttpClient
orRestSharp
. Since I do not know what your code is, here is an example usingHttpClient
:You can do it with
HttpWebRequest
:This works for me.