Simulate a specific CURL in PostMan

前端 未结 7 1763
不思量自难忘°
不思量自难忘° 2020-11-28 02:03

I am using Postman to test some Curl requests to an API server. The API developers gave us the curl command, but I can\'t send it from the Postman. How to make such a reques

相关标签:
7条回答
  • 2020-11-28 02:57

    I tried the approach mentioned by Onkaar Singh,

    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!

    But the problem is it didn't work for the Apis which requires authorisation.

    This was my curl request:

    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
    

    After importing the body got imported correctly, the headers and the Url also got imported. Only the api key 9f4d7f5445e7 which is

    -u 9f4d7f5445e7: https://api.myapp.com/api/v1/event 
    

    in the curl request did not import.

    The way I solved it is, -u is basically used for Authorization. So while using it in Postman, you have to take the API key (which is 9f4d7f5445e7 in this case) and do Base64 Encode. Once encoded it will return the value OWY0ZDdmNTQ0NWU3. Then add a new header, the key name would be Authorization and key value would be Basic OWY0ZDdmNTQ0NWU3. After making that changes, the request worked for me.

    There are online Base64 Encoders available, the one I used is http://www.url-encode-decode.com/base64-encode-decode/

    Hope it helps!!!

    0 讨论(0)
提交回复
热议问题