curl使用总结

curl is a tool to transfer data from or to a server, using one of the supported protocols (DICT, FILE, FTP, FTPS, GOPHER, HTTP, HTTPS, IMAP, IMAPS, LDAP, LDAPS, POP3, POP3S, RTMP, RTSP, SCP, SFTP, SMB, SMBS, SMTP, SMTPS, TELNET and TFTP). The command is designed to work without user interaction.
curl offers a busload of useful tricks like proxy support, user authentication, FTP upload, HTTP post, SSL connections, cookies, file transfer resume, Metalink, and more. As you will see below, the number of features will make your head spin!
curl is powered by libcurl for all transfer-related features. See libcurl(3) for details.这里是引用

常用方法总结

  • 查看网页源码
     $ curl www.sina.com
  • 保存网页源码
    $ curl -o [文件名] www.sina.com
  • 自动跳转
    $ curl -L www.sina.com
  • 显示http response的头信息
    $ curl -i www.sina.com
  • 显示一次http通信的整个过程
    curl -v www.sina.com
  • 查看更详细的通信过程
    $ curl --trace output.txt www.sina.com
    $ curl --trace-ascii output.txt www.sina.com
  • 设置请求状态(curl默认的HTTP动词是GET)
    curl -X POST www.example.com
    $ curl -X DELETE www.example.com
  • 设置请求来源
    提供一个referer字段,表示你是从哪里跳转过来的。
    $ curl --referer http://www.example.com http://www.example.com
  • 增加客户端的设备信息
    ``` $ curl --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” www.sina.com``
  • 增加头信息
    $ curl --header "Content-Type:application/json" http://example.com
  • HTTP认证
    $ curl --user name:password example.com
  • 增加cookie
    curl --cookie "name=xxx" www.example.com
    -c cookie-file可以保存服务器返回的cookie到文件
    curl -c cookie-file http://example.com
    -b cookie-file可以使用这个文件作为cookie信息,进行后续的请求。
    curl -b cookie-file http://example.com
  • 文件上传
    $ curl -F 'img_avatar=@/home/petehouston/hello.txt' http://localhost/upload
    参数-F(–form)会给请求添加 enctype=“multipart/form-data” 参数。
    上传参数img_avatar
    路径/home/petehouston/hello.txt
    上传到 http://localhost/upload`

阮一峰:http://www.ruanyifeng.com/blog/2011/09/curl.html
文件上传:https://www.gonever.com/post/45

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值