【问题标题】:Postman escaping form-data to API causing unexpected token error邮递员将表单数据转义到 API 导致意外的令牌错误
【发布时间】:2015-04-06 20:07:57
【问题描述】:

我正在尝试使用 Postman 来解决我遇到的 API 错误。我正在使用 OAuth 进行身份验证,因此我发布了标题和表单数据。但是,似乎我遇到的错误与表单数据有关。我也尝试将'Content-Type'设置为'application/json; charset=utf-8' 和没有。结果相同。

{
    "error": "795: unexpected token at '------WebKitFormBoundaryoRBw9tLdltLHfrtU\r\nContent-   Disposition: form-data; name=\"topic\"\r\n\r\ncheckouts/update\r\n------WebKitFormBoundaryoRBw9tLdltLHfrtU\r\nContent-Disposition: form-data; name=\"address\"\r\n\r\nhttps://mysite.co/checkout/\r\n------WebKitFormBoundaryoRBw9tLdltLHfrtU\r\nContent-Disposition: form-data; name=\"format\"\r\n\r\njson\r\n------WebKitFormBoundaryoRBw9tLdltLHfrtU--\r\n'"
}

我认为 Postman 会在 API 正确读取我的数据之前对其进行转义。任何想法如何让邮递员停止过早地转义我的数据?似乎没有任何问题。

请求正文:

"webhook":[{"topic": "checkouts/update","address": "https://mysite.co/checkout","format": "json"}]

【问题讨论】:

  • 你能告诉我们请求的正文吗?也许问题就藏在那里。我不认为邮递员是问题。
  • @LaurentJalbertSimard 当然,在这里。
  • 我使用的大多数 API 都需要将 Json 属性包含在 json 对象中,如下所示:{ "webhook":[{"topic": "checkouts/update","address": "https://mysite.co/checkout","format": "json"}] }
  • 这确实是错误。您可以将其添加为答案吗?谢谢

标签: json escaping postman


【解决方案1】:

您需要将 JSON 属性包含在 JSON 对象中,这通常是 API 所期望的。

{ 
    "webhook":[
        {"topic": "checkouts/update","address": "https://mysite.co/checkout","format": "json"}
    ] 
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-10
    • 1970-01-01
    • 1970-01-01
    • 2013-10-09
    • 2016-03-28
    相关资源
    最近更新 更多