curl 简单使用

部分参数

  • -d, --data <data> POST的包体
  • -H, --header <header> 包头
  • -w, --write-out <format>耗时时间
  • -X, --request 发送方式(POST、PUT)

举例

POST application/x-www-form-urlencoded

curl -d "param1=value1&param2=value2" -X POST http://localhost:8080/hello

curl -d "param1=value1&param2=value2" -H "Content-Type: application/x-www-form-urlencoded" -X POST http://localhost:8080/hello

#使用文件
curl -d "@../data/cats.txt" -X POST http://localhost:8080/hello

POST application/json

curl -d '{"key1":"value1", "key2":"value2"}' -H "Content-Type: application/json" -X POST http://localhost:8080/hello

curl -d "@../data/cats.txt" -X POST http://localhost:8080/hello

测试访问支付宝首页

# 环境
$ lsb_release -a
LSB Version:    :base-4.0-amd64:base-4.0-noarch:core-4.0-amd64:core-4.0-noarch
Distributor ID:    CentOS
Description:    CentOS release 6.5 (Final)
Release:    6.5
Codename:    Final

# 测试
$ curl -w "TCP handshake: %{time_connect}, SSL handshake: %{time_appconnect}\n" -so /dev/null https://www.alipay.com
TCP handshake: 0.141, SSL handshake: 0.435

参考

相关推荐