curl
Send JSON:
curl -X POST [URL] \
-H "Content-Type: application/json" \
-d "[JSON data]"
Simulating a web form:
curl [URL] -d "key1=value1&key2=value2"
curl [URL] -F key1=value1 -F key2=value2 -F key2=@filename
curl -O [URL]
curl -O [URL]
5. Send Cookies with Request
You can use the --cookie "name=value" command line parameter to send cookies
to the server with your request. curl will automatically convert this
parameter to the Cookie: name=value request HTTP header.
Curl Send Cookies Example
curl --cookie "name=value" [URL]
6. Ignore SSL Certificate Errors
To ignore SSL certificate validation, you can pass the -k or --insecure
option to the curl command. This option tells curl to perform “unsecured”
SSL connections and file transfers. Data is still transmitted over the SSL
encrypted channel, but curl ignores any security warnings about invalid or
expired SSL certificates and accepts them as valid.
Curl Disable Certificate Validation Example
curl -k [URL]
7. Get only HTTP Headers
The -I or --head option allows curl to fetch only a specific resource’s
HTTP headers (HTTP HEAD method). The HEAD request method is identical to the GET
method, except that the server does not return the body of the HTTP message.
Curl Get Only HTTP Headers Example
curl -I https://reqbin.com/echo
8. Download Multiple Files at Once
You can download multiple files in a single curl command by specifying the
-O parameter multiple times with the desired URLs. If files are downloaded
from the same server, curl will try to reuse the connection.
Curl Download Multiple Files Example
curl -O [URL1] -O [URL2]
9. Do HTTP Authentication
Some websites may require user authentication before providing any content
(username and password). You can pass user credentials to the server using the
-u command line option. By default, curl uses Basic HTTP Authentication. We
can specify other authentication methods using --ntlm or --digest.
Curl HTTP Authentication Example
curl -u username:password [URL]
10. Follow Redirects
By default, curl does not perform 300x redirects. To tell curl to follow
HTTP redirects, use the -L or --location command line option. The server
provides the new address using the Location HTTP header.
Curl Follow Redirect Example
curl -L [URL]
11. Connect via Proxy Server
To establish a connection through a proxy server, pass the required proxy
address using the -x command line parameter. You can pass the username and
password for proxy authentication using the -U command line parameter.
Curl Proxy Example
curl -x [protocol://][host][:port] -U user:password [URL]
12. Make Curl Verbose
The -v option makes curl verbose at runtime and asks curl to provide
detailed information about the progress of the operation, which can be useful
when debugging complex situations.
Curl Verbose Example
curl -v [URL]