Is there a way in command-line curl to POST or GET (insert your favorite HTTP method) data to a URL and include in the raw posted data header values instead of issuing the -H options?
For instance:
$curl --data-binary #- http://server.com/foo/bar <<EOF
X-Foo: Foo
X-Bar: Bar and a lot of random characters
Accept-Encoding: bzip2
My-raw-binary-data-here...
EOF
no, there's no way. curl is a HTTP client that does the HTTP for you. Use 'nc' (netcat) or similar if you want to craft your full request more freely.
Related
How can I force cURL to send an invalid HTTP header, as follows:
curl -k 'https://192.168.1.1/' -H 'Host: 192.168.1.1' -H 'blah' -H 'Accept-Encoding: gzip, deflate, br' -H 'Accept-Language: en-US,en;q=0.8'
When I try the above, cURL helpfully leaves out the invalid header.
You can, but it's slightly more convoluted than that. curl will check that you use a colon and avoid passed in headers that don't have colons. But you can trick curl's colon check by passing in a header with embedded CRLF that then creates two header lines, and one of them can then be without colon.
For example like this:
curl -H "`printf "Foo: bar\r\nblah"`" -v localhost
(-v of course lets you see the actual request curl uses)
I'm using openam OAuth/OpenID for user authentication. As mentioned in the documentations, I could get SSOTokenID as a JSON object by making following HTTP request.
curl -X POST -H "X-OpenAM-Username: demo" -H "X-OpenAM-Password: changeit" -H "Content-Type: application/json" -d '' -k -v https://openam.example.com:8443/openam/json/authenticate?realm=/
Instead of that, I want to get SSOTokenID as the Set-Cookie header value of the HTTP response. Are there anyway that i can do it?
Assuming you are only using an authentication module that accepts a NameCallback and PasswordCallback (as you used in your example), then you can just use the legacy UI zero-page login , you need to disable XUI though
Using your example
curl -X POST -d 'IDToken1=demo&IDToken2=changeit' -k -v https://openam.example.com:8443/openam/UI/Login?realm=/
I'm looking to this snippet of code:
curl -X GET 'https://api.newrelic.com/v2/applications/1622/metrics/data.json' \
-H 'X-Api-Key:30f4ec24a1f7dd9998a536b05840b17f7d42c7c1' -i \
-d 'names[]=EndUser&names[]=EndUser/Apdex&values[]=call_count&values[]=average_response_time&values[]=score&summarize=true'
from "Listing your app ID and metric data".
But curl's man page only talks about -d/--data in the context of POST requests, so, what's really happening here in terms of the HTTP request sent to the server?
-d with GET request just sends a query string, however the endpoint where data are sent must be set to consume application/x-www-form-urlencoded content type - have just checked that.
In general it's weird and I wouldn't implement it in such a way.
When such query is sent to java servlet - the body is accessible via.. getInputStream() method [sic!].
I am sending a curl request pointing to an url containing unsafe characters in it like /test/#/test1.html
I tried below possible ways but was not working. The Url ends when it sees a # in it and the remaining part is not processed. I took a packet capture and found that the url which is sent by curl is just http://<someIP>testsite/ and not http://<someIP>testsite/#/file.html
curl -v -X 'GET' "http://<someIP>/testsite/#/file.html" -D header.txt -o body.txt
curl -v -X 'GET' 'http://<someIP>/testsite/#/file.html' -D header.txt -o body.txt
Could somebody help in answering how to escape the # or how to make curl to send this complete URL ?
What's after # is never sent to the server in the HTTP request. That can only be read through some client side code (js for example). There is no way of making Curl send that.
I am not sure if this helps, but you can try to encode # char to a URL "safe version": %23
Here you can find more useful information: http://www.url-encode-decode.com/
Using REST Server 6.x-2.0-beta3, I'm trying to understand how to post to user.save.
curl -d 'XX' -v http://localhost/services/rest/service_user/save
I've tried to replace XX with:
account{'name':'myname','pass':'mypassword','mail':'my#email.org'}
account = {'name':'myname','pass':'mypassword','mail':'my#email.org'}
account="name=myname,pass=mypassword,mail=myemail.org"
account=name=myname,pass=mypassword,mail=myemail.org
account=myname,mypassword,myemail.org
But none of these seems to be right and finding any documention regarding this is next to impossible.
I've also tried the following:
curl -H "Content-Type: application/json" -d 'account={"name":"myname","pass":"mypassword","email":"123"}' -v http://localhost/services/rest/service_user/save
The error I get in this case is:
HTTP/1.0 406 Not Acceptable: Missing required argument account
Hi I also just started working with this module and wondering how to create content using JSON.
Just been able to create a simple node using this:
Post URL: http://path-to-site/services/rest/node
Request Header: Content-Type: application/json
Request Body: {"type":"story","title":"REST Test","body":"REST using JSON"}
I think you're using the wrong URL
I figured it out:
curl -H “application/x-www-form-urlencoded” -d "sessid=xxxx" -d "account[name]=MyName&account[pass]=mypass&account[mail]=myemail#gmail.com&account[conf_mail]=myemail#gmail.com" -v http://path-to-site/services/rest/service_user/save
You only have to add -d "sessid=xxxx" if you have configured Services to require a session. Make sure in that case to replace xxxx with your actual session id (from system.connect).