CURL 笔记

官网地址:https://curl.haxx.se/

CURL是服务器之间传递数据的工具,支持大多数协议,如我们熟知的FTP,FTPS,HTTP,HTTPS, IMAP,SMTP, TELNET等等。他可以用于获取网站数据,

也可以上传数据。

简单用法:

1. 获取百度的网页内容,这个会返回html。

  curl https:www.baidu.com

2. 获取网站某个端口所返回的内容。比如:8080

  curl http://www.xxx.com:8080/

3. 获取server上的文件

  curl ftps://files.xx.com/a.txt

4. 爬取百度首页的html并将其保存到local的某个文件,使用 curl -o 命令

  curl -o baidu.html https://www.baidu.com

5. 传递authentication头,比如用户名和密码

  curl -u username:password http://www.xx.com

6. curl -v 打印额外信息,这个可以看到请求头和响应头

  curl -v https://www.baidu.com

7. 发送post请求。 curl -d , 使用application/x-www-form-urlencoded MIME类型。

  curl -d "name=foo&pass=1234" http://www.xx.com

8. 上传文件 curl -F

  curl -F "file=@test.txt" http://www.xx.com

9. 设置referrer, curl -e

  curl -v -e  http://www.cnblogs.com/ https://www.baidu.com

10. 传递cookie, curl -b

  curl -b "name=foo" http://www.xx.com

原文地址:https://www.cnblogs.com/gogolee/p/6883261.html