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!
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.
I don't know much about Postman. But I captured what's being sent in a file named /tmp/ncout. Based on this, we see that the Content-Type being sent is application/x-www-form-urlencoded, as you determined, and that the payload being sent is MESSAGE-TYPE=pub.controller.user.created&PAYLOAD=a json object goes here!.
Does that help?
alewin#gobo ~ $ nc -l 8888 >/tmp/ncout 2>&1 </dev/null &
[1] 15259
alewin#gobo ~ $ curl -X POST -i 'http://localhost:8888/' -H X-apiKey:jamesBond007 -d MESSAGE-TYPE="pub.controller.user.created" -d PAYLOAD='a json object goes here!'
curl: (52) Empty reply from server
[1]+ Done nc -l 8888 > /tmp/ncout 2>&1 < /dev/null
alewin#gobo ~ $ cat /tmp/ncout
POST / HTTP/1.1
Host: localhost:8888
User-Agent: curl/7.43.0
Accept: */*
X-apiKey:jamesBond007
Content-Length: 73
Content-Type: application/x-www-form-urlencoded
MESSAGE-TYPE=pub.controller.user.created&PAYLOAD=a json object goes here!alewin#gobo ~ $
Here's an example of how to do this urlencode with python:
Python 2.7.6 (default, Oct 26 2016, 20:30:19)
[GCC 4.8.4] on linux2
Type "help", "copyright", "credits" or "license" for more information.
> data = {'MESSAGE-TYPE': "pub.controller.user.created", 'PAYLOAD': 'a json object goes here!'}
> from urllib import urlencode
> urlencode(data)
PAYLOAD=a+json+object+goes+here%21&MESSAGE-TYPE=pub.controller.user.created
Related
I got a curl that had to be rewritten recently, looking like this:
cmd=$("curl https://exampleurl/query -sX POST -H Authorization: Bearer $ingestToken -H Content-Type: application/json -H Accept: application/json -H Accept-Charset: utf-8 -d {\"queryString\":\"$query\", \"start\": \"$start_time\", \"end\": \"$stop_time
This returns the error "No such file or directory"
I got a working version using eval $cmd, and I have compared the two curl strings generated by each method, and they look the same. Any ideas what is causing the error in this case?
I'm trying to send an "on" signal to a wemo smart plug. I want to send the signal from the linux command line. I know that the request is supposed to look like what I've included below, but I'm not sure what syntax to use. I tried using cURL, but couldn't quite seem to figure it out. Any help would be super appreciated!
POST /upnp/control/basicevent1
SOAPACTION: "urn:Belkin:service:basicevent:1#SetBinaryState"
Content-Type: text/xml; charset="utf-8"
Accept: */*
User-Agent: PostmanRuntime/7.15.2
Cache-Control: no-cache
Host: 192.168.1.116:49153
Accept-Encoding: gzip, deflate
Content-Length: 306
Connection: keep-alive
<?xml version="1.0" encoding="utf-8"?>
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<s:Body>
<u:SetBinaryState xmlns:u="urn:Belkin:service:basicevent:1">
<BinaryState>0</BinaryState>
</u:SetBinaryState>
</s:Body>
</s:Envelope>
I tried putting each of the headers in quotes after a "-H" but then I wasn't sure what to do with the headers that are already quoted. Also, it appeared to be still sending to port 80 even though I included the host header with a different port?
As far as I know, the plug has an IP address but no web address.
Post method have two part (header & body).
You should run cURL command like that:
Send Header:
curl -X POST -H 'SOAPACTION: "urn:Belkin:service:basicevent:1#SetBinaryState"' -H 'Content-Type: text/xml; charset="utf-8"' http://192.168.1.116:49153/upnp/control/basicevent1
With this method, you can head multi header POST.
Send body POST:
And also with that command you can send POST body:
curl -X POST -F '<?xml version="1.0" encoding="utf-8"?>...' http://192.168.1.116:49153/upnp/control/basicevent1
Also, they're available at the following links:
How to send body POST ,
How to send header POST
Command you want at single line:
curl -X POST -H 'SOAPACTION: "urn:Belkin:service:basicevent:1#SetBinaryState"' -H 'Content-Type: text/xml; charset="utf-8"' -H 'Accept: */*' -H 'User-Agent: PostmanRuntime/7.15.2' -H 'Cache-Control: no-cache' -H 'Host: 192.168.1.116:49153' -H 'Accept-Encoding: gzip, deflate' -H 'Content-Length: 306' -H 'Connection: keep-alive' -F '<?xml version="1.0" encoding="utf-8"?>\n<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">\n <s:Body>\n <u:SetBinaryState xmlns:u="urn:Belkin:service:basicevent:1">\n <BinaryState>0</BinaryState>\n </u:SetBinaryState>\n </s:Body>\n</s:Envelope>' http://192.168.1.116:49153/upnp/control/basicevent1
alias
If you think this is a long command, you can set as alias.
For e.g:
alias myPersonalCommandLS='ls -lthra1d'
My service is deployed in docker,the exposed nginx port is 18082;service port is 38087,and I tried both.
while I use command
curl -i -X POST -H 'content-type: text/json' -d #post.json \
http://127.0.0.1:18082/youtu/openliveapi/livedetectfour
return 417
HTTP/1.1 417 Expectation failed
Server: squid/2.7.STABLE9
Date: Tue, 15 Aug 2017 11:57:04 GMT
Content-Type: text/html
Content-Length: 1436
X-Squid-Error: ERR_INVALID_REQ 0
X-Cache: MISS from SK-SQUIDDEV-118
X-Cache-Lookup: NONE from SK-SQUIDDEV-118:8080
Connection: close
But when I add sudo in the front,it return success.
HTTP/1.1 100 Continue
HTTP/1.1 200 OK Server: openresty/1.9.15.1
I really do search and knew while curl post over 1024 bytes,it will first send
expect 100-continue.if server don't support that request, it will return 417 error.
then how can sudo succsess,maybe It is related to nginx mechanism,I'm not familiar with that.thanks.
Since you are using proxy in your corporate setup and the proxy might be insert in your user's bash profile. You can do 3 things
Update ~/.bash_profile or ~/.bashrc
Remove the proxy from your profile and you won't need the proxy
Unset the variables
You can unset the variables before the call
unset http_proxy
unset https_proxy
curl -i -X POST -H 'content-type: text/json' -d #post.json \ http://127.0.0.1:18082/youtu/openliveapi/livedetectfour
Blank the variables for the call
You can set the variables just for that one curl call
http_proxy= https_proxy= curl -i -X POST -H 'content-type: text/json' -d #post.json \ http://127.0.0.1:18082/youtu/openliveapi/livedetectfour
I am using the following command for getting the website data,
curl --data '{"xxxNamespace": "xxxxxx", "h_xxx_action": "xxxxx"}' -i -u username/password -H "Content-Type:application/json" -H "Accept:application/json" -X GET
I would like to download the webpage. But this command results in some html value as o/p,
**HTTP/1.1 200 OK**
Date: Sat, 01 Oct 2016 15:32:19 GMT
Server: Apache/2.2.3 (Red Hat)
Content-ID: -75f83766:15766e71efd:6afa
Set-Cookie: CRN=showWelcomePage%3Dtrue%26automaticPageRefresh%3D30%26displayMode%3Dlist%26useAccessibilityFeatures%3Dfalse%26columnsPerPage%3D3%26linesPerPage%3D15%26timeZoneID%3DWET%26productLocale%3Den%26listViewSeparator%3Dnone%26showOptionSummary%3Dtrue%26showHiddenObjects%3Dfalse%26contentLocale%3Den%26format%3DHTML%26skin%3Dcorporate%26; Domain=.xxx-xx.com; Path=/xx
Connection: close
Transfer-Encoding: chunked
Content-Type: text/html;charset=UTF-8
Kindly help me with the command, Am I doing something wrong ?
I tried with -X GET Option as well, but it returned the same o/p. Kindly help
I'm trying to replicate a database from my local CouchDB installation to IBM Cloudant. I used curl for this, like this -
curl -X POST 'http://10.88.201.198:5984/_replicate'
-d '{
"source":"http://10.88.201.198:5984/temperature-db",
"target":"username:password#username.cloudant.com/temperature-db"
}'
-H "Content-Type: application/json"
-v
The attempt times out, and I get the following message -
upload completely sent off: 255 out of 255 bytes
< HTTP/1.1 500 Internal Server Error
* Server CouchDB/1.6.1 (Erlang OTP/R16B03) is not blacklisted
< Server: CouchDB/1.6.1 (Erlang OTP/R16B03)
< Date: Wed, 27 Apr 2016 09:18:34 GMT
< Content-Type: text/plain; charset=utf-8
< Content-Length: 20
< Cache-Control: must-revalidate
< Proxy-Connection: Keep-Alive
< Connection: Keep-Alive
<
{"error":"timeout"}
How do I go about fixing this ?
you need add the user and password of some user who has permission to replicate and on target miss the 'https://' and use localhost or 0.0.0.0
curl -X POST 'http://username:password#localhost:5984/_replicate'
-d '{
"source":"http://username:password#localhost:5984/temperature-db",
"target":"https://username:password#username.cloudant.com/temperature-db"
}'
-H "Content-Type: application/json"
-v
this maybe help
Chances are your replication is taking a while to complete. To get around this you should use the _replicatordatabase and you can monitor that at your leisure. There is documentation on the cloudant website on how to set up a replication using the _replicator database.