Curl 在PostMan中模拟特定的卷曲

Curl 在PostMan中模拟特定的卷曲,curl,httprequest,postman,Curl,Httprequest,Postman,我正在使用Postman测试一些对API服务器的Curl请求。API开发人员给了我们curl命令,但我不能从邮递员那里发送。如何向邮递员提出这样的要求 curl -X POST "https://api-server.com/API/index.php/member/signin" -d "{"description":"","phone":"","lastname":"","app_version":"2.6.2","firstname":"","password":"my_pass","ci

我正在使用Postman测试一些对API服务器的Curl请求。API开发人员给了我们curl命令,但我不能从邮递员那里发送。如何向邮递员提出这样的要求

curl -X POST "https://api-server.com/API/index.php/member/signin" -d "{"description":"","phone":"","lastname":"","app_version":"2.6.2","firstname":"","password":"my_pass","city":"","apikey":"213","lang":"fr","platform":"1","email":"email@example.com","pseudo":"example"}"

--0xKhTmLbOuNdArY
Content-Disposition: form-data; name="userfile"; filename="profil.jpg"
Content-Type: image/jpeg
Content-Transfer-Encoding: binary

<ffd8ffe0 00104a46 49460001 01010048 ... a00fffd9>

—0xKhTmLbOuNdArY—
curl-X POST”https://api-server.com/API/index.php/member/signin-d“{”description:“,”phone:“,”lastname:“,”app_version:”2.6.2“,”firstname:“,”password:”my_pass“,”city:“,”apikey:”213“,”lang:”fr“,”platform:”1“,”email:”email@example.com,“pseudo”:“示例”}
--0xKhTmLbOuNdArY
内容配置:表单数据;name=“userfile”;filename=“profil.jpg”
内容类型:图像/jpeg
内容传输编码:二进制
-0xKhTmLbOuNdArY-
1)输入
https://api-server.com/API/index.php/member/signin
在url输入框中,从下拉列表中选择
POST

2) 在“标题”选项卡中,输入:

内容类型:图像/jpeg

内容传输编码:二进制

3) 在Body选项卡中,选择
raw
单选按钮并写入:

{“description”:“phone”:“lastname”:“app_version”:“2.6.2”,“firstname”:“pass”:“my_pass”,“city”:“apikey”:“213”,“lang”:“fr”,“platform”:“1”,“email”:email@example.com“,”伪“:“示例”}

选择
表单数据
单选按钮并写入:

key=name-Value=userfile选择
Text

key=filename选择
文件
并上传profile.jpg

一种更简单的方法是:

  • 开放式邮递员
  • 单击左上角的“导入”选项卡
  • 选择“原始文本”选项并粘贴cURL命令
  • 点击导入,您将在邮递员生成器中拥有该命令
  • 单击“发送”发布命令

  • 希望这有帮助

    我尝试了Onkaar Singh提到的方法

  • 开放式邮递员
  • 单击左上角的“导入”选项卡
  • 选择“原始文本”选项并粘贴cURL命令
  • 点击导入,您将在邮递员生成器中拥有该命令 但问题是它不适用于需要授权的API

    这是我的要求:

    curl -v -H "Accept: application/json" -H "Content-type:
    application/json" -X POST -d ' 
    {"customer_id":"812122", "event":"add_to_cart", "email": "abc@def.com", }' 
    -u 9f4d7f5445e7: https://api.myapp.com/api/event
    
    在正确导入正文之后,标题和Url也被导入。仅api键9f4d7f5445e7是

    -u 9f4d7f5445e7: https://api.myapp.com/api/v1/event 
    
    在curl请求中,没有导入

    我解决它的方法是,-u基本上用于授权。因此,在Postman中使用它时,您必须获取API密钥(在本例中为
    9f4d7f5445e7
    )并进行Base64编码。编码后,它将返回值
    OWY0ZDdmNTQ0NWU3
    。然后添加一个新的头,键名为
    Authorization
    ,键值为
    Basic OWY0ZDdmNTQ0NWU3
    。在做出这些改变之后,这个请求对我起了作用

    有在线Base64编码器可用,我使用的是


    希望对你有帮助

    有时候,只要复制cURL,它就包含--compressed。
    In addition to the answer
    1. Open POSTMAN
    2. Click on "import" tab on the upper left side.
    3. Select the Raw Text option and paste your cURL command.
    4. Hit import and you will have the command in your Postman builder!
    5. If -u admin:admin are not imported, just go to the Authorization 
       tab, select Basic Auth -> enter the user name eg admin and password eg admin.
    This will automatically generate Authorization header based on Base64 encoder
    
    在导入->粘贴原始文本-->单击导入时将其删除。 如果您在导入任何cURL时在postman中遇到语法错误,那么它也可以解决这个问题


    通常,当人们从任何代理工具(如Charles)复制cURL时,都会发生这种情况。

    正如上面的多个答案中所述,您可以直接在POSTMAN中导入cURL。但如果URL已授权(或由于某种原因无法工作) 我建议您可以手动将所有数据点作为JSON添加到postman正文中。从cURL中获取API URL

    对于授权部分,只需添加一个授权密钥和base64编码字符串作为值

    例如:

    curl-u rzp_测试26ccbdbfe0e84b:69b2e24411e384f91213f22ahttps://api.razorpay.com/v1/orders    -X POST \--数据“金额=50000”\--数据“货币=印度卢比”\--数据“收据=收据”20“\--数据“付款捕获=1”https://api.razorpay.com/v1/orders

    {
    “金额”:“5000”,
    “货币”:“印度卢比”,
    “收据”:“收据#20”,
    “付款捕获”:“1”
    }

    标题:
    授权:基本cnpwX3Rlc3RfWEk5QW5TU0N3RlhjZ0Y6dURjVThLZ3JiQVVnZ3JNS***U056V25J
    其中,“cnpwX3Rlc3RfWEk5QW5TU0N3RlhjZ0Y6dURjVThLZ3JiQVVnZ3JNS***U056V25J”是“rzp_测试26ccbdbfe0e84b:69b2e24411e384f91213f22a”的编码形式`

    小提示:对于编码,您可以轻松转到chrome控制台(右键单击=>inspect)并键入:
    btoa(“您想要编码的字符串”)
    (或使用邮递员基本授权)

    根据上述答案,它工作得很好

    如果我们在导入中粘贴带有授权数据的curl请求,Postman将自动设置所有标题。如果需要,我们只在请求体中传递行JSON数据,或者通过请求体中的表单数据上传图像

    这只是一个例子。您的API应该是不同的(如果您的API允许)


    当您使用Chrome
    copy as cURL(bash)
    并在Postman中导入时,您需要执行以下操作:

  • 删除
    --压缩的
    选项
  • -d

  • 否则,您将得到cURL的
    无效格式
    错误。

    直到看到这篇文章,我才知道您可以这样做。谢谢这正是我想要的。谢谢我试过了,但部分奏效了。这是我的curl请求:
    curl-v-H“Accept:application/json”-H“Content type:application/json”-X POST-d'{“customer_id”:“812122”,“event”:“add_to_cart”,“email”:abc@def.com“,}'-u 9f4d7f5445e7:https://api.myapp.com/api/event
    导入后,正确导入车身,标题和Url也已导入。仅api键9f4d7f5445e7是
    -u 9f4d7f5445e7:https://api.myapp.com/api/v1/event
    中的curl请求未导入,或者可能是邮递员跳过了它。知道怎么解决吗?我自己想办法导入curl cmd。但我花了一些时间才找到导入curl的页面的位置,导入文件/cmd时似乎什么都没有发生。然后,您需要单击屏幕上的“代码”按钮
    curl -X POST 'https://verifyUser.abc.com/api/v1/verification' \
        -H 'secret: secret' \
        -H 'email: user@gmail.com' \
        -H 'accept: application/json, text/plain, */*' \
        -H 'authorizationtoken: bearer' \
        -F 'referenceFilePath= Add file path' \
        --compressed