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!].
Related
I am trying to get my custom built HTTP Post request to execute the following call to twilio
curl -X POST 'https://api.twilio.com/2010-04-01/Accounts/xxxxx/Messages.json' \
--data-urlencode 'To=+15558675309' \
--data-urlencode 'From=+15017250604' \
--data-urlencode 'Body=This is the ship that made the Kessel Run in fourteen parsecs?' \
-d 'MediaUrl=https://c1.staticflickr.com/3/2899/14341091933_1e92e62d12_b.jpg' \
-u xxxxx:your_auth_token
My custom built request accepts an URL, headers and a body, similar to the HTTP Post form at Hurl.it.
How do I translate the portions
--data-urlencode
and
-d
into my URL, headers and body?
Example: The -u part I put into a header with "Authorization: Basic ", and it worked perfectly, the server recognises me. I just can't get it to recognise the From, To, Body parts.
Tks!
Twilio developer evangelist here.
Both the -d and --data-urlencode flags indicate adding data to the POST request body. The data also needs to be url encoded. When the request is made, all the url encoded data is concatenated with ampersands and sent as the body.
In the case of your example, the POST request body would end up looking like this:
To=%2B15558675309&From=%2B15017250604&Body=This%20is%20the%20ship%20that%20made%20the%20Kessel%20Run%20in%20fourteen%20parsecs%3F&MediaUrl=https%3A%2F%2Fc1.staticflickr.com%2F3%2F2899%2F14341091933_1e92e62d12_b.jpg
Let me know if that helps at all.
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 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/
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.
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).