http-curl
跨域
# 跨域测试
curl -i -X OPTIONS https://api.xxx.xyz/admin/captcha \
-H "Origin: https://xxxxx1.xxx.xyz"
curl -i -X POST https://api.xxx.xyz/admin/captcha \
-H "Origin: https://xxxxx1.xxx.xyz" \
-d '{"a":"1"}'提交和上传
# POST
curl -d "name=abc" http://127.0.0.1:2000/echoback
# 表单提交
curl -d "user=nickwolfe&password=12345" http://10.248.13.7:18001/registerNameajax.htm
# json
curl -i -X POST -H 'Content-type':'application/json' \
-d "userName=user1&password=zz123456" http://192.168.183.100:8050/nature/login
curl -i -X POST -H 'Content-type':'multipart/form-data' \
-d "userName=user1&password=zz123456" http://192.168.183.100:8050/nature/login
curl -i -X POST -H 'Content-type':'application/x-www-form-urlencoded' \
-d "userName=user1&password=zz123456" http://192.168.183.100:8050/nature/login
curl -X POST http://localhost:8080/api -H "Content-Type: application/json" -d '{"a":"b"}'
# json - file
curl -X POST http://localhost:8080/api -H "Content-Type: application/json" -d @sendfile.json综合
# 添加 host 头
curl -H "Host: minio.services.wait" http://10.2.1.75:80/static/css/style.css
# 修改 agent 和 xff
curl -i --user-agent myagent \
-H "X-Forwarded-For: 1.1.1.1, 2.2.2.2" \
-H "Host: www.baidu.com" \
http://10.1.2.1:18001/
# 请求 ipv6 服务
curl -6 -g http://[2409:8081:1120:6010:7002::12c]:17101
curl -6 -g -k https://[2409:8081:1120:6010:7002::20]:443/services/LoginForWap?wsdl
# socket5
curl http://myip.ipip.net --socks5 127.0.0.1:15733
# http 获取返回码
curl -sL -w "%{http_code}\\n" www.baidu.com -o /dev/null
curl -i -s -o /dev/null -w "%{http_code}\n" http://blog.services.wait
curl -s --connect-timeout 5 -o /dev/null -w "%{http_code}" "https://www.baidu.com"
# GET 请求多条参数的情况下对中文进行 urlencode 转码
curl -G --data-urlencode 'phone=1111111,222222' \
--data-urlencode 'body= 【服务器故障】 10.26.2.20 故障, 请及时检查处理 ' \
'http://10.1.2.1:9002/api/v1/sms/send'curl 其它参数
curk -k # 跳过 https 证书
-e referer
-e http://shop.10086.cn
--interface eth0
使用指定网卡执行网络脚本
# 执行网络脚本, 不需要下载
curl http://xxx.com/xx/xx.sh | bash
# 传递参数方式
curl -s http://xxx.com/xx/xx.sh | bash -s arg1 arg2
bash <(curl -s http://xxx.com/xx/xx.sh) arg1 arg2
# 具名参 - 区分是 bash 的参数, 还是 脚本的参数, 使用 -- 作为区分
# -- 前面的比如 -s 属于 bash, 后面的 -x abc -y xyz 属于远程脚本的参数
curl -L http://xxx.com/xx/xx.sh | bash -s -- -x abc -y xyz小技巧
# 压缩请求
curl -i -H "Accept-Encoding: gzip" http://xxxxx.xxx
# 跟踪 url 重定向后的链接
curl -i -L http://10.35.18.166:8050/naturalMan/userQuit
# 超时控制, tcp 2s 超时, 数据包 20s 超时
curl -i --connect-timeout 2 -m 20 http://10.230.88.61:11003/services
# 查询耗时情况
-w 'time_connect %{time_connect}\ntime_starttransfer %{time_starttransfer}\ntime_total %{time_total}\n'
# 设置 cookie
curl -b "sign=UnbvXIf06L3wtSwHMw3C" http://127.0.0.1
# 循环测试某接口
for i in $(seq 2000);
do
curl -sL -w "%{http_code}\\n" --connect-timeout 3 http://10.1.170.1:9086/uac -o /dev/null >> ~/a.log
echo $i
sleep 1
done
# 测试 tcp 端口的开放
curl -v telnet://192.168.5.9:22最后更新于