How to add json to RestSharp POST request

I have tried like this and it working fine, Add Bearer with token

 request.AddHeader("cache-control", "no-cache");
 request.AddHeader("authorization", "Bearer " + "your token key");
 request.AddHeader("accept", "application/json");

This should work:

request.AddParameter("application/json; charset=utf-8", JsonConvert.SerializeObject(yourObject), ParameterType.RequestBody);

If you directly add the serialized object, the problem is the Json convert is adding "\" before each ".


I've ran into this problem as well. Try something like this instead of AddJsonBody.

request.AddParameter("application/json", locationJSON, ParameterType.RequestBody);

Tags:

C#

Json

Restsharp