Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Constructing an HTTP POST request using Curl and Postman

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?

like image 747
ksl Avatar asked Aug 18 '14 13:08

ksl


2 Answers

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

like image 81
ashish bansal Avatar answered Nov 08 '22 03:11

ashish bansal


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.

like image 42
Yuvika Avatar answered Nov 08 '22 05:11

Yuvika