curl – transfer a URL
curl is a tool to transfer data from or to a server, using one of the supported protocols (DICT, FILE, FTP, FTPS, GOPHER, HTTP, HTTPS, IMAP, IMAPS, LDAP, LDAPS, POP3, POP3S, RTMP, RTSP, SCP, SFTP, SMB, SMBS, SMTP, SMTPS, TELNET and TFTP). The command is designed to work without user interaction.
curl offers a busload of useful tricks like proxy support, user authentication, FTP upload, HTTP post, SSL connections, cookies, file transfer resume, Metalink, and more.
-C, allow resume the interrupted download
-d, –data <data>
(HTTP) Sends the specified data in a POST request to the HTTP server, in the same way that a browser does when a user has filled in an HTML form and presses the submit button. This will cause curl to pass the data to the server using the content-type application/x-www-form-urlencoded. Compare to -F, –form.
-d, –data is the same as –data-ascii. –data-raw is almost the same but does not have a special interpretation of the @ character. To post data purely binary, you should instead use the –data-binary option. To URL-encode the value of a form field you may use –data-urlencode.
If any of these options is used more than once on the same command line, the data pieces specified will be merged together with a separating &-symbol. Thus, using ‘-d name=daniel -d skill=lousy’ would generate a post chunk that looks like ‘name=daniel&skill=lousy’.
If you start the data with the letter @, the rest should be a file name to read the data from, or – if you want curl to read the data from stdin. Multiple files can also be specified. Posting data from a file named ‘foobar’ would thus be done with –data @foobar. When –data is told to read from a file like that, carriage returns and newlines will be stripped out. If you don’t want the @ character to have a special interpretation use –data-raw instead.
(SSL) This option explicitly allows curl to perform “insecure” SSL connections and transfers. All SSL connections are attempted to be made secure by using the CA certificate bundle installed by default. This makes all connections considered “insecure” fail unless -k, –insecure is used.
-L option, it will allow to follow URL redirection.
*o (lowercase o) the result will be saved in the filename provided in the command line
*O (uppercase O) the filename in the URL will be taken and it will be used as the filename to store the result
$curl -o mygettext.html http://www.gnu.org/software/gettext/manual/gettext.html
$ curl -O http://www.gnu.org/software/gettext/manual/gettext.html ($ curl -O URL1 -O URL2)
-x option. We need to specify the host and port of the proxy.
$ curl -x proxysever.test.com:3128 http://google.co.in
Be more verbose/talkative during the operation. Useful for debugging and seeing what’s going on “under the hood”. A line starting with ‘>’ means “header data” sent by curl, ‘<‘ means “header data” received by curl that is hidden in normal cases, and a line starting with ‘*’ means additional info provided by curl.
Note that if you only want HTTP headers in the output, -i, –include might be the option you’re looking for.
If you think this option still doesn’t give you enough details, consider using –trace or –trace-ascii instead.
This option overrides previous uses of –trace-ascii or –trace.
Use -s, –silent to make curl quiet.
-H, –header <header>
(HTTP) Extra header to include in the request when sending HTTP to a server. You may specify any number of extra headers. Note that if you should add a custom header that has the same name as one of the internal ones curl would use, your externally set header will be used instead of the internal one. This allows you to make even trickier stuff than curl would normally do. You should not replace internally set headers without knowing perfectly well what you’re doing. Remove an internal header by giving a replacement without content on the right side of the colon, as in: -H “Host:”. If you send the custom header with no-value then its header must be terminated with a semicolon, such as -H “X-Custom-Header;” to send “X-Custom-Header:”.
curl will make sure that each header you add/replace is sent with the proper end-of-line marker, you should thus not add that as a part of the header content: do not add newlines or carriage returns, they will only mess things up for you.
See also the -A, –user-agent and -e, –referer options.
Starting in 7.37.0, you need –proxy-header to send custom headers intended for a proxy.
-X, –request <command>
(HTTP) Specifies a custom request method to use when communicating with the HTTP server. The specified request method will be used instead of the method otherwise used (which defaults to GET). Read the HTTP 1.1 specification for details and explanations. Common additional HTTP requests include PUT and DELETE, but related technologies like WebDAV offers PROPFIND, COPY, MOVE and more.
Normally you don’t need this option. All sorts of GET, HEAD, POST and PUT requests are rather invoked by using dedicated command line options.
#curl -XGET -kv -H “`get-oauth-creds –header`” “https://testserver/networkcategories/”
#curl -XGET -kv -H “`get-oauth-creds –header`” “https://testserver/networkcategories?page=5&size=200&metadata=true” |jpp
#curl -XGET -kv -H “`get-oauth-creds –header`” “https://testserver/networkcategories?fieldName=naturalId&page=1″
#curl -XPOST -kv -H “`get-oauth-creds –header`” -H “Content-Type:application/json” -d@networkCategory.json “https://testserver/networkcategories/”
#curl -XPUT -kv -H”if-Match: 1234567890″ -H “`get-oauth-creds –header`” -H “Content-Type:application/json” -d@networkCategory.json “https://testserver/networkcategories/”
#curl -XPATCH -kv -H”if-Match: 987654321″ -H “`get-oauth-creds –header” `” -H “Content-Type:application/json” -d@networkCategory.json “https://testserver/networkcategories/”
One might want to
POST their message to a message board, and then
PUT additional content into their message at a later date. POST create the contents and PUT updates the contents.
#curl -XDELETE -kv -H “`get-oauth-creds –header`” “https://testserver/networkcategories/”
curl --data "param1=value1¶m2=value2" https://example.com/resource.cgi
curl --form "email@example.com" https://example.com/resource.cgi
Multipart with fields and a filename:
curl --form "firstname.lastname@example.org;filename=desired-filename.txt" --form param1=value1 --form param2=value2 https://example.com/resource.cgi
curl --data '' https://example.com/resource.cgi
curl -X POST https://example.com/resource.cgi
curl --request POST https://example.com/resource.cgi
For a RESTful HTTP POST containing XML:
curl -X POST -d @filename.txt http://example.com/path/to/resource --header "Content-Type:text/xml"
or for JSON, use this:
curl -X POST -d @filename.txt http://example.com/path/to/resource --header "Content-Type:application/json"