1.安装
cURL is a command-line utility for transferring data from or to a remote server using one of the supported protocols.
It is installed by default on macOS and most Linux distributions.
wget http://curl.haxx.se/download/curl-7.19.6.tar.gz
tar -zxvf curl-7.19.6.tar.gz
cd curl-7.19.6
./configure --prefix=/usr/local/curl
make
make install
无法访问互联网下载的用户,可以在互联网下载好,导入到内网。
2.使用
2.1用法
curl -X POST [options] [URL]
The -X
option specifies which HTTP request method will be used when communicating with the remote server.
2.2 提交multipart/form-data数据
下边是文件上传的例子
# 文件上传
curl -X POST url -F 'sbbh=A65DADBE166594FA70B622E29C45F935' -F file=@/data/zzzd/reg_record.mp3'
When the -F
option is used, curl
sends the data using the multipart/form-data
Content-Type.
2.3 提交application/x-www-form-urlencoded数据
curl -X POST -d 'name=linuxize' -d 'email=linuxize@example.com' https://example.com/contact.php
If the
-d
option is used more than once you can merge the data using the&
symbol
curl -X POST -d 'name=linuxize&email=linuxize@example.com' https://example.com/contact.php
2.4 指定特定的Content-Type
To set a specific header or Content-Type use the
-H
option. The following command sets the POST request type toapplication/json
and sends a JSON object
curl -X POST -H "Content-Type: application/json" -d '{"name": "linuxize", "email": "linuxize@example.com"}' https://example/contact