【问题标题】:API endpoint works with JSON, not with raw textAPI 端点适用于 JSON,而不适用于原始文本
【发布时间】:2020-04-23 00:59:15
【问题描述】:

我正在使用 Postman 访问 API 端点。我将body 输入的设置设置为raw+JSON 并传递了以下正文:

{
  "a": 1,
  "b": 2,
  "c": 3
}

这很好用。但是,当我将其设置为raw+Text 并通过时

a=1&b=2&c=3返回如下错误:

"Invalid payload Error: There was an error deserializing the object of type InTowConnect._default35+RequestRequest. Encountered unexpected character 'a'."

有谁知道我该如何调试这个?

【问题讨论】:

  • a=1&b=2&c=3 对于此类数据,使用内容类型为application/x-www-form-urlencoded。传递您的 a,b,c xxx-www-form-url-encoded 键值对。
  • @AkshayBande 当我更改为xxx-www-form-url-encoded 时,邮递员会强迫我在单独的框中输入每个参数。所以我不能输入为a=1&b=2&c=3

标签: json api postman endpoint


【解决方案1】:

JSON 是它自己的标准,而不是文本字符串。您发送到的解析器很可能不接受除预期 JSON 之外的协议。 JSON != 文本。

【讨论】:

    猜你喜欢
    • 2017-11-18
    • 1970-01-01
    • 2019-06-19
    • 2015-05-29
    • 1970-01-01
    • 1970-01-01
    • 2011-10-03
    • 2015-10-05
    • 2012-04-20
    相关资源
    最近更新 更多