希曼日记

curl

本页目录 11
  1. 发送Form表单与参数
  2. -H
  3. -X
  4. -d
  5. -u
  6. -G
  7. -b
  8. -i
  9. -I
  10. -L
  11. 参考

发送Form表单与参数

curl -X POST http://127.0.0.1/register -d'account=student2&password=123456' -F 'avatar=@../example/images/avatar.svg'

对应的http测试文件

### 注册
PUT {{url}}/register
Content-Type: multipart/form-data; boundary=boundary
Content-Type: application/json

--boundary
Content-Disposition: form-data; name="avatar"; filename="avatar.svg"

// 发送文件
< ../example/images/avatar.svg
--boundary
Content-Disposition: form-data; name="account";

student2

--boundary
Content-Disposition: form-data; name="password";

123456

--boundary--

-H

-H参数添加 HTTP 请求的标头。

curl -H 'Content-Type': 'application/json; charset=utf-8' -H 'Secret-Message: xyzzy' https://google.com

-X

-X参数指定 HTTP 请求的方法。

-d

-d参数用于发送 POST 请求的数据体。

curl -d'login=emma&password=123'-X POST https://google.com/login

curl -d 'login=emma' -d 'password=123' -X POST  https://google.com/login

-u

-u参数用来设置服务器认证的用户名和密码

-G

-G参数用来构造 URL 的查询字符串。

curl -G -d 'q=kitties' -d 'count=20' https://google.com/search

-b

-b参数用来向服务器发送 Cookie。

curl -b 'foo=bar' https://google.com

-i

-i参数打印出服务器回应的 HTTP 标头

-I

-I参数向服务器发出 HEAD 请求,然会将服务器返回的 HTTP 标头打印出来

-L

-L参数会让 HTTP 请求跟随服务器的重定向。curl 默认不跟随重定向。

参考

阮一峰