本文讲述curl
工具的相关内容
简介
curl 是一个用于传输数据的工具,支持众多协议(DICT, FILE, FTP, FTPS, GOPHER, HTTP, HTTPS, IMAP, IMAPS, LDAP, LDAPS, POP3, POP3S, RTMP, RTSP, SCP, SFTP, SMTP, SMTPS, TELNET and TFTP)。该命令被设计为无需用户交互即可工作
curl 提供大量有用的功能,如代理支持、用户认证、FTP上传、HTTP POST、SSL连接、Cookies、文件断点续传等等,如你所见,它大量的特征将使你头晕目眩
curl 中关于传输相关的特征基于 libcurl,详情参见
man 3 libcurl
——翻译自
man curl
中的DESCRIPTION
部分
HTTP
GET
1 2 curl -i -H "Accept: application/json" -H "Content-Type: application/json" -X GET http://hostname/resource curl -H "Accept: application/xml" -H "Content-Type: application/xml" -X GET http://hostname/resource
POST
For posting data:
1 curl --data "param1=value1¶m2=value2" http://hostname/resourceFor file upload:
1 curl --form "fileupload=@filename.txt" http://hostname/resourceRESTful HTTP Post:
1 curl -X POST -d @filename http://hostname/resourceFor logging into a site (auth):
1 2 curl -d "username=admin&password=admin&submit=Login" --dump-header headers http://localhost/Login curl -L -b headers http://localhost/
Pretty Printing
JSON
Python
If you use pip and python, you can install pjson package by running this command:
1 pip install pjsonUsage:
1 curl -i -H "Accept: application/json" -H "Content-Type: application/json" -X GET http://hostname/resource | pjsonIf you use Python 2.6+, json tool is bundled within.
Usage:
1 curl -i -H "Accept: application/json" -H "Content-Type: application/json" -X GET http://hostname/resource | python -m json.tool
链接
下面总结了本文中使用的所有链接: