feat: add curl.md sheatsheet.
				
					
				
			This commit is contained in:
		@@ -63,7 +63,8 @@ Quick Reference
 | 
			
		||||
 | 
			
		||||
## Linux 命令
 | 
			
		||||
 | 
			
		||||
[Chmod](./docs/chmod.md)<!--rehype:style=background: rgb(239 68 113/var(\-\-bg\-opacity));-->
 | 
			
		||||
[Curl](./docs/curl.md)<!--rehype:style=background: rgb(16 185 129/var(\-\-bg\-opacity));-->
 | 
			
		||||
[Chmod](./docs/chmod.md)<!--rehype:style=background: rgb(16 185 129/var(\-\-bg\-opacity));-->
 | 
			
		||||
[Cron](./docs/cron.md)<!--rehype:style=background: rgb(239 68 68/var(\-\-bg\-opacity));-->
 | 
			
		||||
[Git](./docs/git.md)<!--rehype:style=background: rgb(215 89 62/var(\-\-bg\-opacity));-->
 | 
			
		||||
[Grep](./docs/grep.md)<!--rehype:style=background: rgb(16 185 129/var(\-\-bg\-opacity));-->
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										176
									
								
								docs/curl.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										176
									
								
								docs/curl.md
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,176 @@
 | 
			
		||||
Curl 备忘清单
 | 
			
		||||
===
 | 
			
		||||
 | 
			
		||||
此 [Curl](https://github.com/curl/curl) 备忘清单包含命令和一些常见的 Curl 技巧示例。
 | 
			
		||||
 | 
			
		||||
入门
 | 
			
		||||
----
 | 
			
		||||
 | 
			
		||||
### 介绍
 | 
			
		||||
 | 
			
		||||
Curl 是一种在服务器之间传输数据的工具,支持协议,包括 HTTP/FTP/IMAP/LDAP/POP3/SCP/SFTP/SMB/SMTP 等
 | 
			
		||||
 | 
			
		||||
- [Curl GitHub 源码仓库](https://github.com/curl/curl) _(github.com)_
 | 
			
		||||
- [Curl 官方网站](https://curl.se/) _(curl.se)_
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
### Options
 | 
			
		||||
<!--rehype:wrap-class=col-span-2 row-span-2-->
 | 
			
		||||
 | 
			
		||||
```bash
 | 
			
		||||
-o <file>    # --output: 写入文件
 | 
			
		||||
-u user:pass # --user: 验证
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
---
 | 
			
		||||
 | 
			
		||||
```bash
 | 
			
		||||
-v           # --verbose: 在操作期间使 curl 冗长
 | 
			
		||||
-vv          # 更冗长
 | 
			
		||||
-s           # --silent: 不显示进度表或错误
 | 
			
		||||
-S           # --show-error: 与 --silent (-sS) 一起使用时,显示错误但没有进度表
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
---
 | 
			
		||||
 | 
			
		||||
```bash
 | 
			
		||||
-i           # --include: 在输出中包含 HTTP 标头
 | 
			
		||||
-I           # --head: 仅标头
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
### 请求
 | 
			
		||||
 | 
			
		||||
```bash
 | 
			
		||||
-X POST # --request
 | 
			
		||||
-L  # 如果页面重定向,请点击链接
 | 
			
		||||
-F  # --form: multipart/form-data 的 HTTP POST 数据
 | 
			
		||||
```
 | 
			
		||||
<!--rehype:className=wrap-text -->
 | 
			
		||||
 | 
			
		||||
### 数据
 | 
			
		||||
 | 
			
		||||
```bash
 | 
			
		||||
# --data: HTTP post 数据
 | 
			
		||||
# URL 编码(例如,status="Hello")
 | 
			
		||||
-d 'data'
 | 
			
		||||
 | 
			
		||||
# --data 通过文件
 | 
			
		||||
-d @file
 | 
			
		||||
 | 
			
		||||
# --get: 通过 get 发送 -d 数据
 | 
			
		||||
-G
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
### 头信息 Headers
 | 
			
		||||
 | 
			
		||||
```bash
 | 
			
		||||
-A <str>         # --user-agent
 | 
			
		||||
 | 
			
		||||
-b name=val      # --cookie
 | 
			
		||||
 | 
			
		||||
-b FILE          # --cookie
 | 
			
		||||
 | 
			
		||||
-H "X-Foo: y"    # --header
 | 
			
		||||
 | 
			
		||||
--compressed     # 使用 deflate/gzip
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
### SSL
 | 
			
		||||
 | 
			
		||||
```bash
 | 
			
		||||
    --cacert <file>
 | 
			
		||||
    --capath <dir>
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
```bash
 | 
			
		||||
-E, --cert <cert>     # --cert: 客户端证书文件
 | 
			
		||||
    --cert-type       # der/pem/eng
 | 
			
		||||
-k, --insecure        # 对于自签名证书
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
#### 安装
 | 
			
		||||
 | 
			
		||||
```bash
 | 
			
		||||
apk add --update curl  # alpine linux 中安装
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
示例
 | 
			
		||||
----
 | 
			
		||||
<!--rehype:body-class=cols-6-->
 | 
			
		||||
 | 
			
		||||
### CURL GET/HEAD
 | 
			
		||||
<!--rehype:wrap-class=col-span-4 row-span-2-->
 | 
			
		||||
 | 
			
		||||
命令 | 说明
 | 
			
		||||
:- | :-
 | 
			
		||||
`curl -I https://www.baidu.com` | `curl` 发请求
 | 
			
		||||
`curl -v -I https://www.baidu.com` | 带有详细信息的 `curl` 发请求
 | 
			
		||||
`curl -X GET https://www.baidu.com` | 使用显式 http 方法进行 `curl`
 | 
			
		||||
`curl --noproxy 127.0.0.1 http://www.stackoverflow.com` | 没有 http 代理的 `curl`
 | 
			
		||||
`curl --connect-timeout 10 -I -k https://www.baidu.com` | `curl` 默认没有超时
 | 
			
		||||
`curl --verbose --header "Host: www.mytest.com:8182" www.baidu.com` | `curl` 得到额外的标题
 | 
			
		||||
`curl -k -v https://www.google.com` | `curl` 获取带有标题的响应
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
### 多文件上传
 | 
			
		||||
<!--rehype:wrap-class=col-span-2-->
 | 
			
		||||
 | 
			
		||||
```bash
 | 
			
		||||
$ curl -v -include \
 | 
			
		||||
    --form key1=value1 \
 | 
			
		||||
    --form upload=@localfilename URL
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
### 为 curl 响应美化 json 输出
 | 
			
		||||
<!--rehype:wrap-class=col-span-2-->
 | 
			
		||||
 | 
			
		||||
```bash
 | 
			
		||||
$ curl -XGET http://${elasticsearch_ip}:9200/_cluster/nodes | python -m json.tool
 | 
			
		||||
```
 | 
			
		||||
<!--rehype:className=wrap-text -->
 | 
			
		||||
 | 
			
		||||
### CURL POST
 | 
			
		||||
<!--rehype:wrap-class=col-span-4-->
 | 
			
		||||
 | 
			
		||||
命令 | 说明
 | 
			
		||||
:- | :-
 | 
			
		||||
`curl -d "name=username&password=123456" <URL>` | `curl` 发请求
 | 
			
		||||
`curl <URL> -H "content-type: application/json" -d "{ \"woof\": \"bark\"}"` | `curl` 发送 json
 | 
			
		||||
 | 
			
		||||
### CURL 脚本安装 rvm
 | 
			
		||||
<!--rehype:wrap-class=col-span-2-->
 | 
			
		||||
 | 
			
		||||
```shell
 | 
			
		||||
curl -sSL https://get.rvm.io | bash
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
### CURL 高级
 | 
			
		||||
<!--rehype:wrap-class=col-span-6-->
 | 
			
		||||
 | 
			
		||||
命令 | 说明
 | 
			
		||||
:- | :-
 | 
			
		||||
`curl -L -s http://ipecho.net/plain, curl -L -s http://whatismijnip.nl` | 获取我的公共 `IP`
 | 
			
		||||
`curl -u $username:$password http://repo.dennyzhang.com/README.txt` | 带凭证的 `curl` 
 | 
			
		||||
`curl -v -F key1=value1 -F upload=@localfilename <URL>` | `curl` 上传
 | 
			
		||||
`curl -k -v --http2 https://www.google.com/` | 使用 http2 curl 
 | 
			
		||||
`curl -T cryptopp552.zip -u test:test ftp://10.32.99.187/` | curl `ftp` 上传
 | 
			
		||||
`curl -u test:test ftp://10.32.99.187/cryptopp552.zip -o cryptopp552.zip` | curl `ftp` 下载
 | 
			
		||||
`curl -v -u admin:admin123 --upload-file package1.zip http://mysever:8081/dir/package1.zip` | 使用凭证 `curl` 上传
 | 
			
		||||
 | 
			
		||||
### 检查网站响应时间
 | 
			
		||||
<!--rehype:wrap-class=col-span-4-->
 | 
			
		||||
 | 
			
		||||
```shell
 | 
			
		||||
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 -->
 | 
			
		||||
 | 
			
		||||
### 使用 Curl 检查远程资源是否可用
 | 
			
		||||
<!--rehype:wrap-class=col-span-2-->
 | 
			
		||||
 | 
			
		||||
```bash
 | 
			
		||||
curl -o /dev/null --silent -Iw "%{http_code}" https://example.com/my.remote.tarball.gz
 | 
			
		||||
```
 | 
			
		||||
<!--rehype:className=wrap-text -->
 | 
			
		||||
@@ -450,6 +450,8 @@ a.text-grey {
 | 
			
		||||
 | 
			
		||||
.wrap-header.h1wrap .wrap-body {
 | 
			
		||||
  color: var(--color-fg-subtle);
 | 
			
		||||
  max-width: 850px;
 | 
			
		||||
  margin: 0 auto;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
.wrap-header.h1wrap > h1 {
 | 
			
		||||
@@ -638,7 +640,7 @@ body:not(.home) .h2wrap-body > .wrap:hover .h3wrap > h3 a::after {
 | 
			
		||||
}
 | 
			
		||||
.h2wrap-body ul.style-timeline li::before {
 | 
			
		||||
  color: #228e6c;
 | 
			
		||||
  background-color: #fff;
 | 
			
		||||
  background-color: var(--color-canvas-default);
 | 
			
		||||
  counter-increment: stepCount;
 | 
			
		||||
  content: counter(stepCount);
 | 
			
		||||
  border-radius: initial;
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user