curl 常用命名整理

让人想犯罪 __ 提交于 2019-12-10 11:12:58

基础命令

详细命名可参考 https://man.linuxde.net/curl

查看网页源码 curl www.sina.com

-o 保存网页相当于 wget curl -o [文件名] www.sina.com

-L 抓取自动跳转页面,www.sina.com 会自动跳转到www.sina.com.cn ,该参数会返回跳转后的内容 curl -L www.sina.com

-i 查看response头,保括Content内容

-I 只查看response头

-v 显示一次http通信的整个过程,包括端口连接和http request头信息

-X 传递curl动作,curl默认动作是get,使用 -X 传入其他动作:curl -X POST www.example.com

–trace 或 --trace-ascii 会将更详细的通信过程输出到文件,curl --trace output.txt www.sina.com

–referer 有时你需要在http request头信息中,提供一个referer字段,表示你是从哪里跳转过来的, curl --referer http://www.example.com http://www.example.com

–user-agent 设置客户端的设备信息例如:Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_0 like Mac OS X; en-us) AppleWebKit/532.9 (KHTML, like Gecko) Version/4.0.5 Mobile/8A293 Safari/6531.22.7 curl --user-agent “[User Agent]” [URL]

–cookie 使用–cookie参数,可以让curl发送cookie, curl --cookie “name=xxx” www.example.com,

-c cookie-file可以保存服务器返回的cookie到文件,-b cookie-file可以使用这个文件作为cookie信息,进行后续的请求. curl -c cookies http://example.com, curl -b cookies http://example.com

Post 提交

curl 表单提交

curl -X POST --data “data=xxx” example.com/form.cgi

对表单数据编码 --data-urlencode

curl -X POST–data-urlencode “date=April 1” example.com/form.cgi

curl post xml报文

echo 'xxxx '| curl -X POST -H ‘Content-type:text/xml’ -d @- http://1.1.1.1:8081/loginregistration/register

cat 1.xml | curl -X POST -H ‘Content-type:text/xml’ -d @- http://1.1.1.1::8081/httpInvokeServlet
注解: xxxx是xml报文内容 1.xml 报文文件 @- 读取管道符内容

curl post json 报文

curl -H “Content-Type:application/json” -X POST --data ‘xxxx’ http://1.1.1.1:18080/
cat 1.json | curl -H “Content-Type:application/json” -X POST -d @- http://1.1.1.1:8081/httpInvokeServlet

注解: xxxx是json报文内容 1.json 报文文件 @- 读取管道符内容

代理方式

使用普通转发代理访问:
curl -x http://127.0.0.1:80 -H ‘Content-Type:application/json’ -v http://www.baidu.com
使用隧道代理方式访问:
curl -x http://127.0.0.1:80 -x CONNECT -v http://www.baidu.com

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!