gpt4 book ai didi

c# - 如何使用Restsharp正确添加Request Payload?

转载 作者:太空宇宙 更新时间:2023-11-03 14:42:58 27 4
gpt4 key购买 nike

我正在尝试使用 RestSharp 来使用查询 rest,但我总是收到 Bad Request 响应。代码:

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}

我尝试在 Postman 中使用 Raw body 返回预期结果,但在 C# 中没有。帮助表示赞赏。

最佳答案

请检查您的 Json 格式。Payload json 格式可能不正确。

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

1.您的浏览器发送了本服务器无法理解的请求。2.无效网址3.由于语法格式错误,服务器无法理解该请求。客户不应该在没有修改的情况下重复请求4.请求主机名无效。

关于c# - 如何使用Restsharp正确添加Request Payload?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55937453/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com