我正在使用邮差测试一些Curl请求到API服务器。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—

当前回答

当你使用Chrome复制cURL (bash)和导入在邮差,你需要做以下事情:

删除——压缩选项 用-d替换——data-raw

否则,cURL错误将导致无效格式。

其他回答

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

一个更简单的方法是:

开放的邮递员 点击左上角的“导入”标签。 选择Raw Text选项并粘贴cURL命令。 点击导入,您将在您的邮差构建器中拥有命令! 单击Send发送命令

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

对于授权部分-只需添加一个授权密钥和基于64编码的字符串作为值。

例子:

curl -u rzp_test_26ccbdbfe0e84b:69b2e24411e384f91213f22a \ https://api.razorpay.com/v1/orders -X POST \——data "金额=50000" \——data "货币=INR" \——data "收据=收据#20" \——data "payment_capture=1" https://api.razorpay.com/v1/orders

{ “金额”:“5000”, “货币”:“INR”, “收据”:“收据#20”, “payment_capture”:“1” }

标题: 授权:基本cnpwX3Rlc3RfWEk5QW5TU0N3RlhjZ0Y6dURjVThLZ3JiQVVnZ3JNS * * * U056V25J 其中“cnpwX3Rlc3RfWEk5QW5TU0N3RlhjZ0Y6dURjVThLZ3JiQVVnZ3JNS***U056V25J”是“rzp_test_26ccbdbfe0e84b:69b2e24411e384f91213f22a”的编码形式

小提示:对于编码,你可以很容易地去你的chrome控制台(右键单击=> inspect)并输入: Btoa(“你想编码的字符串”)(或使用邮递员基本授权)

当你使用Chrome复制cURL (bash)和导入在邮差,你需要做以下事情:

删除——压缩选项 用-d替换——data-raw

否则,cURL错误将导致无效格式。

我尝试了Onkaar Singh提到的方法,

开放的邮递员 点击左上角的“导入”标签。 选择Raw Text选项并粘贴cURL命令。 点击导入,您将在您的邮差构建器中拥有命令!

但问题是,它并不适用于需要授权的Apis。

这是我的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请求中没有导入。

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

有在线的Base64编码器可用,我使用的是http://www.url-encode-decode.com/base64-encode-decode/

希望能有所帮助!!