How to add json to RestSharp POST request

前端 未结 3 1818
日久生厌
日久生厌 2021-01-01 19:22

I have the following JSON string that is passed into my c# code as a string parameter - AddLocation(string locationJSON):

{\"accountId\":\"57abb4d6aad4\",\"a         


        
相关标签:
3条回答
  • 2021-01-01 19:52

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

    request.AddParameter("application/json", locationJSON, ParameterType.RequestBody);
    
    0 讨论(0)
  • 2021-01-01 19:54

    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");
    
    0 讨论(0)
  • 2021-01-01 20:06

    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 ".

    0 讨论(0)
提交回复
热议问题