docker run --rm -it docker.io/curlimages/curl:latest cat /etc/os-release

curl --verbose --header 'Host: www.example.com' 'http://10.1.1.36:8000/the_url_to_test'
curl --verbose -X POST --header "Cookie: JSESSIONID=136zm5iif8o2e8tcelqk9nd6e"  http://www.lizi.com:30010/j_spring_security_logout

# 使用socks代理
ssh sshUser@sshHost -C -f -N -g -D [localBindIp:]localBindPort
curl --socks5 localhost:13659 https://www.baidu.com/
curl --proxy socks5h://localhost:13659 https://www.baidu.com/
export ALL_PROXY=socks5h://127.0.0.1:13659

export http_proxy=http://prod11.kingsilk.net:81/
export https_proxy=http://prod11.kingsilk.net:81/
curl -v https://www.baidu.com/


export http_proxy=http://localhost:81/
curl -v https://www.baidu.com/

export https_proxy=https://localhost:1443/
export https_proxy=socks://192.168.0.12:19999
curl -v https://www.baidu.com/


# 跟随302跳转
-L

# 禁止显示进度条
-s

# echo server
socat -v tcp-l:1234,fork exec:'/bin/echo'


# 只显示 http 头
curl -s -D - www.baidu.com -o /dev/null

# 以 GET 请求 配合 -d 处理URL参数
curl -v -X GET -G \
    --data-urlencode a=aa中 \
    -d b=bb国 \
    "https://www.baidu.com/?x=xx#/yyy?c=cc"

# http basic 认证
curl -v -u username:password https://www.baidu.com/

# 查看post请求中body的数据 : --trace-ascii /dev/stdout
# 以 multipart/form-data 形式post提交数据
curl https://www.baidu.com \
    -F k1=v1 \
    -F k2=@file \
    --trace-ascii /dev/stdout

# 以 application/x-www-form-urlencoded 形式post提交数据
curl https://www.baidu.com \
    -d k1=v1 \
    --data-urlencod ddd@/tmp/data.json \
    --data-urlencode k2='v 2' \
    --trace-ascii /dev/stdout

# 以 application/x-www-form-urlencoded 形式post提交url encode 的json数据
curl https://www.baidu.com \
    --data-urlencode param="`cat add.json`" \
    --trace-ascii /dev/stdout

# 以 二进制方式提交
curl https://www.baidu.com \
    --data-binary param="`cat add.json`" \



# POST JSON
curl -X POST http://baidu.com  \
    -H "Content-Type: application/json" \
    -d @- <<'EOF'
  {
    "username":"xyz",
    "password":"xyz"
}
EOF

curl -X POST \
    -H "Content-Type: application/json" \
    -d '{"username":"xyz","password":"xyz"}' \
    http://localhost:3000/api/login


curl -X POST \
    -H "Content-Type: application/json" \
    -d @./path/to/file.json \
    http://localhost:3000/api/login



# POST XML
curl -X POST \
    -H "Content-Type: application/xml" \
    -d '<run><log encoding="hexBinary">4142430A</log><result>0</result><duration>2000</duration></run>' \
    http://user:pass@myhost/hudson/job/_jobName_/postBuildResult

# 下载文件
curl -fsSL https://dlcdn.apache.org/maven/maven-3/3.9.5/binaries/apache-maven-3.9.5-bin.tar.gz -o /tmp/apache-maven-3.9.5-bin.tar.gz
tar zxvf /tmp/apache-maven-3.9.5-bin.tar.gz

curl -fsSL https://dlcdn.apache.org/maven/maven-3/3.9.5/binaries/apache-maven-3.9.5-bin.tar.gz  | tar -C /tmp -zx

# 下载 *.tag.gz 并解压
TAG=v0.1.15
curl -fSL https://github.com/vozlt/nginx-module-vts/archive/${TAG}.tar.gz | tar -zx


# 最简单的一个 ECHO 服务器
ncat -l 2000 -k -c 'xargs -n1 echo'


# 检查给定的网址是否支持 HTTP/2
curl -sI http://curl.se -o/dev/null -w '%{http_version}\n'            # 1.1
curl -sI https://curl.se -o/dev/null -w '%{http_version}\n'           # 2
curl -sI --http3 https://curl.se -o/dev/null -w '%{http_version}\n'   # 3  (需要 curl >= 7.88.1)

socket

[Docker Engine API (1.42)](https://docs.docker.com/engine/api/v1.42/)

podman run --rm -it alpine:latest sh
curl -v --unix-socket /Users/zll/.local/share/containers/podman/machine/qemu/podman.sock http:/v1.42/containers/json

client ssl cipher suites

curl https://www.howsmyssl.com/a/check

query parameter URL转义/URL编码

# curl 从 7.87.0 开始支持 --url-query,这是最干净的方式, curl 会自动做 URL 编码,你不需要手动处理空格、& 等字符。
curl "http://api.example.com/search" \
  --url-query "q=hello world" \
  --url-query "tag=AI & 大模型"

# 如果你用的 curl 版本较老(< 7.87.0),可以用 -G + --data-urlencode 的组合:
# -G 告诉 curl 把 --data 系列参数附加到 URL 上作为 query string,而不是放到 POST body 里。
# 要查看你的 curl 版本是否支持 --url-query,可以直接跑 curl --version | head -1。
curl -G "http://api.example.com/search" \
  --data-urlencode "q=hello world" \
  --data-urlencode "tag=AI & 大模型"

# 用 CURL 生成万恒的URL,并保存到 shell 变量中
# curl 不支持 `--dry-run`, 但可以通过 `-I` 只发送 header 来仅仅进行轻量的请求,以便获取 完整URL
url=$(
    curl -I -s -o /dev/null -w "%{url_effective}" \
        "http://api.example.com/search" \
        --url-query "q=hello world" \
        --url-query "tag=AI & 大模型"
)
echo "$url"

# 如果不使用curl,则可以使用jq来生成
base="http://api.example.com/search"
url=$(jq -n \
  --arg base "$base" \
  --arg q "hello world" \
  --arg tag "AI & 大模型" \
  '"\($base)?q=\($q|@uri)&tag=\($tag|@uri)"' -r)