How to add json to RestSharp POST request

本小妞迷上赌 提交于 2019-12-01 03:09:26

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

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

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

PK-1825

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");
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!