Tuesday, December 12, 2017

Curl- Useful commands

Multiple Header:

Usage: curl -H “Host:localhost” -H “Content-Type:text/xml” http://www.mysite.com


Url/Param Encoding

curl -v -H 'Authorization: ESA YW40VFVmQlhyZmFlSmtCSjplejMyOXFDZTRkektOMnNp' -X GET 'http://10.40.19.8/ext/consumer/rmsj/int/1.0/item/search' -x 218.251.242.132:80 -G --data-urlencode 'itemName="'

Notice : -G --data-urlencode 'itemName="'


Http request with Proxy: (small -x)


An HTTP proxy is a proxy that the client speaks HTTP with to get the transfer done. curl will,
by default, assume that a host you point out with -x or --proxy is an HTTP proxy, and
unless you also specify a port number it will default to port 3128 (and the reason for that
particular port number is purely historical).

If you want to request the example.com web page using a proxy on 192.168.0.1 port 8080, a
command line could look like:


curl -x 192.168.0.1:8080 http:/example.com/



Request method (big -X)

The first line of the request includes the method - sometimes also referred to as "the verb".
When doing a simple GET request as this command line would do:

curl http://example.com/file

…the initial request line looks like this:

GET /file HTTP/1.1
You can tell curl to change the method into something else by using the -X or --request
command-line options followed by the actual method name. You can, for example, send a

DELETE instead of GET like this:

curl http://example.com/file -X DELETE

This command-line option only changes the text in the outgoing request, it does not change
any behavior. This is particularly important if you, for example, ask curl to send a HEAD with
-X , as HEAD is specified to send all the headers a GET response would get but never
send a response body, even if the headers otherwise imply that one would come. So, adding
-X HEAD to a command line that would otherwise do a GET will cause curl to hang, waiting
for a response body that won't come.

When asking curl to perform HTTP transfers, it will pick the correct method based on the
option so you should only very rarely have to explicitly ask for it with -X . It should also be
noted that when curl follows redirects like asked to with -L , the request method set with -
X will be sent even on the subsequent redirects.



HTTP POST ( -d or --data)

POST is the HTTP method that was invented to send data to a receiving web application,
and it is how most common HTML forms on the web works. It usually sends a chunk of
relatively small amounts of data to the receiver.

When the data is sent by a browser after data have been filled in a form, it will send it "URL
encoded", as a serialized name=value pairs separated with ampersand symbols ('&'). You
send such data with curl's -d or --data option like this:

curl -d 'name=admin&shoesize=12' http://example.com/

When specifying multiple -d options on the command line, curl will concatenate them and
insert ampersands in between, so the above example could also be made like this:

curl -d name=admin -d shoesize=12 http://example.com/

If the amount of data to send isn't really fit to put in a mere string on the command line, you
can also read it off a file name in standard curl style:

curl -d @filename http://example.com

Content-Type

POSTing with curl's  -d  option will make it include a default header that looks like Content-
Type: application/x-www-form-urlencoded . That's what your typical browser will use for a
plain POST.
Many receivers of POST data don't care about or check the Content-Type header.
If that header is not good enough for you, you should, of course, replace that and instead
provide the correct one. Such as if you POST JSON to a server and want to more accurately
tell the server about what the content is:

curl -d '{json}' -H 'Content-Type: application/json' https://example.com


No comments:

Post a Comment

5 Strategies for Getting More Work Done in Less Time

Summary.    You’ve got more to do than could possibly get done with your current work style. You’ve prioritized. You’ve planned. You’ve dele...