C# 如何使用Restsharp正确添加请求负载?

C# 如何使用Restsharp正确添加请求负载?,c#,restsharp,C#,Restsharp,我试图使用RestSharp来使用查询rest,但我总是得到错误的请求响应。守则: var url = "https://gql.tokopedia.com/graphql/"; var request = new RestRequest(Method.POST); var client = new RestClient(url); request.RequestFormat = DataFormat.Json; request.AddHeader("cache-control", "no-c

我试图使用RestSharp来使用查询rest,但我总是得到错误的请求响应。守则:

var url = "https://gql.tokopedia.com/graphql/";
var request = new RestRequest(Method.POST);
var client = new RestClient(url);

request.RequestFormat = DataFormat.Json;
request.AddHeader("cache-control", "no-cache");
request.AddHeader("Content-Type", "application/json");
request.AddBody(payLoad);
IRestResponse response = client.Execute(request);
请求类型为POST,请求负载为JSON(如Chrome所示),其值如下:

{"variables":{"sid":"987569","page":1,"perPage":80,"etalaseId":"etalase","sort":1},"query":"query ShopProducts($sid: String!, $page: Int, $perPage: Int, $keyword: String, $etalaseId: String,  $sort: Int){\n  GetShopProduct(shopID: $sid, filter: { page: $page, perPage: $perPage, fkeyword: $keyword, fmenu: $etalaseId, sort: $sort }){\n    status\n    errors\n    links {\n      prev\n      next\n    }\n    data {\n      name\n      product_url\n      product_id\n      price {\n        text_idr\n      }\n      primary_image{\n        original\n        thumbnail\n        resize300\n      }\n      flags{\n        isSold\n        isPreorder\n        isWholesale\n        isWishlist\n      }\n      campaign {\n        discounted_percentage\n        original_price_fmt\n        start_date\n        end_date\n      }\n      label{\n        color_hex\n        content\n      }\n      badge{\n        title\n        image_url\n      }\n      stats{\n        reviewCount\n        rating\n      }\n      category{\n        id\n      }\n    }\n  }\n}","operationName":null}

我在《邮递员》中尝试了使用原始body返回预期结果,但在c#中没有。感谢您的帮助。

请检查您的Json格式。有效负载Json格式可能不正确

由于以下原因收到错误请求(400)

1.您的浏览器发送了此服务器无法理解的请求。 2.无效的URL 3.由于语法错误,服务器无法理解该请求。未经修改,客户端不应重复请求 4.请求主机名无效。

您可以使用Fiddler(或类似工具)比较来自Postman和您的应用程序的传出请求,看看有什么不同吗?