I am trying to convert the curl request below into an HTTP request for the postman tool. The postman tool might not really matter in this question. Please tell me how I can convert curl to http.
curl -X POST -i 'https://a-webservice.com' -H X-apiKey:jamesBond007 -d MESSAGE-TYPE="pub.controller.user.created" -d PAYLOAD='a json object goes here!'
What I tried/learned: – Set headers content-type: json/application, X-apiKey
- from curl docs, -d option means we need to set content-type application/x-www-form-urlencoded
Postman lets me set the request body using ONLY 1 of the 4 options- form-data, x-www-form-urlencoded, raw, binary. Can you show how I can convert the two -d options of curl into these options ?
I am confused how to put it all together.
Thanks!
Advertisement
Answer
The format of application/x-www-form-urlencoded
data is just the same as a query string, so:
MESSAGE-TYPE=pub.controller.user.created&PAYLOAD=a json object goes here!
To confirm, you can dump the request data with curl
itself, using the --trace-ascii
option:
curl --trace-ascii - -X POST -i 'https://a-webservice.com' -H X-apiKey:jamesBond007 -d MESSAGE-TYPE="pub.controller.user.created" -d PAYLOAD='a json object goes here!'
--trace-ascii
takes a filename as an argument but if you give it -
it will dump to stdout
.
The output for the above invocation will include something like this:
=> Send header, 168 bytes (0xa8) 0000: POST / HTTP/1.1 0011: Host: example.com 0024: User-Agent: curl/7.51.0 003d: Accept: */* 004a: X-apiKey:jamesBond007 0061: Content-Length: 73 0075: Content-Type: application/x-www-form-urlencoded 00a6: => Send data, 73 bytes (0x49) 0000: MESSAGE-TYPE=pub.controller.user.created&PAYLOAD=a json object g 0040: oes here! == Info: upload completely sent off: 73 out of 73 bytes
So the same as what’s confirmed in the answer at Convert curl request into http request? that uses nc
, but confirmed just using curl
itself, with the --trace-ascii
option.