【问题标题】:Convert cURL to Postman REST Call将 cURL 转换为 Postman REST 调用
【发布时间】:2019-03-06 16:13:15
【问题描述】:

如何将以下 cURL 命令转换为 Postman 休息调用?

curl -X POST abc.com/input.import 
        -H 'content-type: application/x-www-form-urlencoded'
        --data-urlencode "apiKey=123-456"
        --data-urlencode "secret=12/her"
        --data-urlencode "userKey=ApUR"
        --data-urlencode "email=fakeImportedAccount@example.com"
        --data-urlencode "profile={'firstName':'John','lastName':'Kira'}" 

我尝试了以下方法:

网址:(POST) abc.com/input.import

标头:Content-Type:application/json

主体:

{
    "apiKey":"123-456",
    "userKey":"ApUR",
    "secret":"12/her",
    "email":"fakeImportedAccount@example.com",
    "profile": {
        "firstName":"John",
        "lastName":"Kira"
    }
}

编辑:Postman 中的原始正文格式是必需的。导入以"x-www-form-urlencoded" 形式创建请求

【问题讨论】:

  • 不要将 content-type 设置为 applicaiton/json。在正文部分,选择 application/x-www-form-urlencoded,它会自动为您设置标题。然后只需设置不同的键值对。
  • 更新了问题。
  • 在每个示例中,您使用不同的内容类型
  • @Evert 他们不是可兑换的吗?

标签: rest curl postman


【解决方案1】:

内容类型不是application/json,而是application/x-www-form-urlencoded。您需要做的是在正文选项卡中,选择application/x-www-form-urlencoded。将自动为您设置内容类型标题。刚开始添加键/值对( --data-urlencoded 参数)

更新

不相关,但对于那些正在寻找一种发布 JSON 的方法(这很常见)的人,您可以使用“原始”单选按钮,然后手动将 JSON 输入到他们提供的窗口中。您还可以将Content-Type 标头设置为application/json

【讨论】:

    【解决方案2】:

    我终于发现:我必须对每个键值进行 url-encode 并使用 Content-Type:application/x-www-form-urlencoded 发送它。

    标头:application/x-www-form-urlencoded 正文:

    {
      "apiKey":"123-456",
      "userKey":"ApUR",
      "secret":"12%2Fher",
      "email":"fakeImportedAccount%40example.com",
      "profile":{
         "firstName":"John",
         "lastName":"Kira"
      }
    }
    

    【讨论】:

    • 这对身体来说似乎不正确。这真的适合你吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-01-17
    • 2017-01-26
    • 1970-01-01
    • 2019-07-14
    • 2016-05-29
    • 2018-01-30
    • 2021-02-10
    相关资源
    最近更新 更多