Curl
Commonly used for transferring data over multiple protocols like HTTPS, FTP, LDAP, etc., curl is particularly useful for debugging and troubleshooting connectivity and endpoint-related issues in environments and use-cases that lack proper tooling.
Options
Options | Values | Description |
---|---|---|
-X <REQUEST_TYPE> --request | GET, POST, PUT, DELETE | Specify the request type. Default GET |
-v | NA | Enable verbose logging |
-k --insecure | NA | Disable Certificate checking (SSL/TLS disable) |
-o <FILE_NAME> --output | NA | Specify output file to which response is written |
-d 'RAW_DATA' --data-raw | NA | Request body for POST request |
-C | NA | Resume interrupted downloads |
-L | NA | Follow redirects |
-u <USER_NAME>:<PASSWORD> | NA | Basic authentication |
--header '<HEADER_VALUE>' -H <HEADER_VALUE> | NA | Provide header value REST request |
-b <DATA> --cookie "name1:value1; name2: value2" | NA | Specify cookie headers |
--basic | NA | Explicitly specify authentication type |
--negotiate | NA | Specify kerberos authentication type |
--http1.0 | NA | Force to use http 1.0 |
--http1.1 | NA | Force to use http 1.1 |
--http2 | NA | Force to use http 2.0 |
--progress-bar | NA | Shows transfer progress bar |
Packages and Install
Quick installation of the curl utility on different operating systems.
OS | Package Install CMD |
---|---|
Debian/Ubuntu | apt install curl -y |
CentOS/Fedora(DNF, MicroDNF, RPM) | rpm install curl OR dnf install curl |
Arch (Pacman) | pacman -Sy curl |
Alpine (APK-Docker) | apk –no-cache add curl |
Examples
- Download a image file
curl -o logo.png https://reqbin.com/static/img/logo.png
- Sending a custom header to the request
curl --header 'Host: targetapplication.com' https://192.0.0.1:8080/
- Make a GET request with basic authentication.
curl -u user_name:password -X GET https//192.0.0.1:8000/someendpoint
- Make a POST request with JWT authentication, skip HTTPS check, and provide JSON data.
curl -k -X POST https://localhost:8088/endpoint \
-H 'Accept: application/json' \
-H "Authorization: Bearer ${TOKEN}" \
--data '{"name": "John"}'
- Make a REST request with Kerberos-enabled authentication, skip TLS, and enable verbose logging.
# Fetch the TGT token for kerberos principal
klist -kt /etc/krb5.keytab
kinit -kt /etc/krb5.keytab <PRINCIPAL>
klist
# Send the SPNEGO enabled request using the earlier fetched token
curl -kv --negotiate -u : <URL>
- Download a file with progress.
curl --progress-bar -O https://localhost:8080/wp-content/temp.zip
- Send a request using cookies.
curl -b "sessionid=123456" https://localhost:8080