fix: curl format

Fix modifier spacing and a little capitalization
This commit is contained in:
FireIsGood committed 2024-05-16 14:40:38 -07:00
1 parent 7a69e64e6d
commit 8dd19e6bc3
1 file changed
+37 -90
+37 -90
View File
@@ -3,23 +3,22 @@ title: Curl
date: 2023-01-03 15:18:34
background: bg-slate-600
tags:
- url
- request
- url
- request
categories:
- Linux Command
- Linux Command
intro: |
This [Curl](https://github.com/curl/curl) cheat sheet contains commands and examples of some common Curl tricks.
This [Curl](https://github.com/curl/curl) cheat sheet contains commands and examples of some common Curl tricks.
plugins:
- copyCode
- copyCode
---
Getting Started
---------------
## Getting Started
### Introduction
`Curl` is a tool for transferring data between servers, supporting protocols, including:
`Curl` is a tool for transferring data between servers, supporting protocols, including:
- HTTP
- HTTPS
- FTP
@@ -31,14 +30,14 @@ Getting Started
- SMB
- SMTP
- etc...
{.cols-3 .marker-none}
----------------------------------------------------------------
---
- [Curl GitHub source repository](https://github.com/curl/curl) _(github.com)_
- [Curl Official Website](https://curl.se/) _(curl.se)_
### Options {.col-span-2 row-span-2}
```bash
@@ -62,8 +61,6 @@ Getting Started
-I # --head: header only
```
### Request
```bash
@@ -71,9 +68,6 @@ Getting Started
-L # If the page redirects, follow the link
-F # --form: HTTP POST data for multipart/form-data
```
<!--rehype:className=wrap-text -->
### data
@@ -89,8 +83,6 @@ Getting Started
-G
```
### Header information Headers
```bash
@@ -106,8 +98,6 @@ Getting Started
--compressed # use deflate/gzip
```
### SSL
```bash
@@ -121,33 +111,25 @@ Getting Started
-k, --insecure # For self-signed certificates
```
#### Install
```bash
apk add --update curl # install in alpine linux
```
Example {.cols-6}
----
<!--rehype:body-class=cols-6-->
## Example {.cols-6}
### CURL GET/HEAD {.col-span-4 .row-span-2}
command | description
:-| :-
`curl -I https://cheatsheets.zip` | `curl` sends a request
`curl -v -I https://cheatsheets.zip` | `curl` request with details
`curl -X GET https://cheatsheets.zip` | use explicit http method for `curl`
`curl --noproxy 127.0.0.1 http://www.stackoverflow.com` | `curl` without http proxy
`curl --connect-timeout 10 -I -k https://cheatsheets.zip` | `curl` has no timeout by default
`curl --verbose --header "Host: www.mytest.com:8182" cheatsheets.zip` | `curl` get extra header
`curl -k -v https://www.google.com` | `curl` get response with headers
<!--rehype:class=auto-wrap-->
| command | description |
| :-------------------------------------------------------------------- | :---------------------------------- |
| `curl -I https://cheatsheets.zip` | `curl` sends a request |
| `curl -v -I https://cheatsheets.zip` | `curl` request with details |
| `curl -X GET https://cheatsheets.zip` | use explicit http method for `curl` |
| `curl --noproxy 127.0.0.1 http://www.stackoverflow.com` | `curl` without http proxy |
| `curl --connect-timeout 10 -I -k https://cheatsheets.zip` | `curl` has no timeout by default |
| `curl --verbose --header "Host: www.mytest.com:8182" cheatsheets.zip` | `curl` get extra header |
| `curl -k -v https://www.google.com` | `curl` get response with headers |
### Multiple file upload {.col-span-2}
@@ -157,46 +139,36 @@ $ curl -v --include \
--form upload=@localfilename URL
```
### Prettify json output for curl response {.col-span-2}
```bash
$ curl -XGET http://${elasticsearch_ip}:9200/_cluster/nodes | python -m json.tool
```
<!--rehype:className=wrap-text -->
### CURL POST {.col-span-4}
command | description
:-| :-
`curl -d "name=username&password=123456" <URL>` | `curl` send request
`curl <URL> -H "content-type: application/json" -d "{ \"woof\": \"bark\"}"` | `curl` sends json
<!--rehype:class=auto-wrap-->
| command | description |
| :-------------------------------------------------------------------------- | :------------------ |
| `curl -d "name=username&password=123456" <URL>` | `curl` send request |
| `curl <URL> -H "content-type: application/json" -d "{ \"woof\": \"bark\"}"` | `curl` sends json |
### CURL script install rvm {.col-span-2}
```shell
curl -sSL https://get.rvm.io | bash
```
### CURL Advanced {.col-span-6}
command | description
:-| :-
`curl -L -s http://ipecho.net/plain, curl -L -s http://whatismijnip.nl` | get my public `IP`
`curl -u $username:$password http://repo.dennyzhang.com/README.txt` | `curl` with credentials
`curl -v -F key1=value1 -F upload=@localfilename <URL>` | `curl` upload
`curl -k -v --http2 https://www.google.com/` | use http2 curl
`curl -T cryptopp552.zip -u test:test ftp://10.32.99.187/` | curl `ftp` upload
`curl -u test:test ftp://10.32.99.187/cryptopp552.zip -o cryptopp552.zip` | curl `ftp` download
`curl -v -u admin:admin123 --upload-file package1.zip http://mysever:8081/dir/package1.zip` | upload with credentials `curl`
<!--rehype:class=auto-wrap-->
| command | description |
| :------------------------------------------------------------------------------------------ | :----------------------------- |
| `curl -L -s http://ipecho.net/plain, curl -L -s http://whatismijnip.nl` | get my public `IP` |
| `curl -u $username:$password http://repo.dennyzhang.com/README.txt` | `curl` with credentials |
| `curl -v -F key1=value1 -F upload=@localfilename <URL>` | `curl` upload |
| `curl -k -v --http2 https://www.google.com/` | use http2 curl |
| `curl -T cryptopp552.zip -u test:test ftp://10.32.99.187/` | curl `ftp` upload |
| `curl -u test:test ftp://10.32.99.187/cryptopp552.zip -o cryptopp552.zip` | curl `ftp` download |
| `curl -v -u admin:admin123 --upload-file package1.zip http://mysever:8081/dir/package1.zip` | upload with credentials `curl` |
### Check website response time {.col-span-4}
@@ -205,18 +177,12 @@ curl -s -w \
'\nLookup time:\t%{time_namelookup}\nConnect time:\t%{time_connect}\nAppCon time:\t%{time_appconnect}\nRedirect time:\t%{time_redirect}\nPreXfer time:\t%{time_pretransfer }\nStartXfer time:\t%{time_starttransfer}\n\nTotal time:\t%{time_total}\n' \
-o /dev/null https://www.google.com
```
<!--rehype:className=wrap-text -->
### Use Curl to check if a remote resource is available {.col-span-2}
```bash
curl -o /dev/null --silent -Iw "%{http_code}" https://example.com/my.remote.tarball.gz
```
<!--rehype:className=wrap-text -->
### Downloading file {.col-span-3}
@@ -230,56 +196,44 @@ while read i; do curl https://example.com/"${i}" \
Download all PNG files from the site (using GNU grep)
### Download the file, save the file without changing its name {.col-span-3}
```bash
curl --remote-name "https://example.com/linux-distro.iso"
```
rename file
Rename file
```bash
curl --remote-name "http://example.com/index.html" --output foo.html
```
### continue partial download {.col-span-3}
```bash
curl --remote-name --continue-at -"https://example.com/linux-distro.iso"
```
<!--rehype:className=wrap-text -->
### Download files from multiple domains {.col-span-3}
```bash
curl "https://www.{example,w3,iana}.org/index.html" --output "file_#1.html"
```
<!--rehype:className=wrap-text -->
### Download a series of files {.col-span-3}
```bash
curl "https://{foo,bar}.com/file_[1-4].webp" --output "#1_#2.webp"
```
<!--rehype:className=wrap-text -->
Download a series of files (output `foo_file1.webp`, `foo_file2.webp...bar_file1_webp`, etc.)
### Redirect output to file {.col-span-3}
```bash
$ curl http://url/file > file
```
### Basic Authentication {.col-span-3}
```bash
@@ -287,8 +241,6 @@ $ curl --user username:password http://example.com/
$ curl -u username:password http://example.com/
```
### Write to file instead of stdout {.col-span-2}
```bash
@@ -296,8 +248,6 @@ $ curl -o file http://url/file
$ curl --output file http://url/file
```
### Download header information
```bash
@@ -305,22 +255,19 @@ $ curl -I url
# display header information
```
### Write output to a file named remote_file {.col-span-2}
```bash
$ curl -o file http://url/file
$ curl --output file http://url/file
```
### Execute remote script {.col-span-2}
```bash
$ curl -s http://url/myscript.sh
```
### Configuration file {.col-span-2}
```bash