Constructing an HTTP POST request using Curl and Postman

40,661

Solution 1

POST requests post data as part of the request body and GET requests via URL parameters. If you choose the form data option in postman you can pass it the same way (request body) in postman as well. How are parameters sent in an HTTP POST request? may be worth reading.

Solution 2

Constructing curl , python request , using HTTP POST

  1. Open postman client and click on code [Below save button ] refer snapshot .Click on save button

  2. when click on code another window appears . refer snapshot .change http post to curl

  3. similarly you can generate various other request [curl , python ,java , php ] refer snapshot

generate code snippets

You can refer below link http://jmeterblogb.blogspot.in/2016/11/constructing-curl-from-python-http-php.html

Share:
40,661
ksl
Author by

ksl

Updated on November 11, 2020

Comments

  • ksl
    ksl over 3 years

    I have been using curl & Postman on Chrome to send http POST requests with one variable to an simple HTTP server I have running and I have noticed that they construct the requests slightly differently. Apologies if I might have used any incorrect terminology in constructing the question - I'm still learning this stuff.

    Using Postman, the request is constructed by putting a '?' between the resource name and the variable. E.g.

    http://192.168.0.2:9999/1/command?a=b
    

    However, the following curl command:

    curl -X POST http://192.168.0.2:9999/1/command --data a=b 
    

    does not put a '?' between the resource name and the variable.

    The result is that the HTTP server interprets the requests differently.

    In the first case, the body of the request is empty and in the second case the body contains a=b.

    Which version is correct?