linux之curl get、post

  1. GET请求
$curl 'http://127.0.0.1:5028/test' -v
 1. About to connect() to 127.0.0.1 port 5028 (#0)
 2.   Trying 127.0.0.1...
 3. Connected to 127.0.0.1 (127.0.0.1) port 5028 (#0)
> GET /test HTTP/1.1
> User-Agent: curl/7.29.0
> Host: 127.0.0.1:5028
> Accept: */*
>
 4. HTTP 1.0, assume close after body
< HTTP/1.0 200 OK
< Content-Type: text/html; charset=utf-8
< Content-Length: 3
< Server: Werkzeug/0.10.4 Python/2.7.8
< Date: Sun, 22 Aug 2021 07:50:21 GMT
<
 5. Closing connection 0
get
  1. POST请求
    • 增加-d给到参数即可,eg:curl 'http://127.0.0.1:5028/test' -d 'action=post'
      说明:一般此时使用的是request.form接收参数,比如request.form["action"]
    • 服务器若接收的是json类的参数,则需增加HEADER-H 'Content-Type:application/json',eg:curl 'http://127.0.0.1:5028/test' -H 'Content-Type:application/json' -d '{"action":"post"}'
      说明:
      1、-H 默认的是Content-Type: application/x-www-form-urlencoded,因此要显式声明-H 'Content-Type:application/json'
      2、一般此时使用的是request.json接收参数,比如request.json["action"]

具体示例如下

$curl 'http://127.0.0.1:5028/test' -d 'action=post' -v
* About to connect() to 127.0.0.1 port 5028 (#0)
*   Trying 127.0.0.1...
* Connected to 127.0.0.1 (127.0.0.1) port 5028 (#0)
> POST /test HTTP/1.1
> User-Agent: curl/7.29.0
> Host: 127.0.0.1:5028
> Accept: */*
> Content-Length: 11
> Content-Type: application/x-www-form-urlencoded
>
* upload completely sent off: 11 out of 11 bytes
* HTTP 1.0, assume close after body
< HTTP/1.0 200 OK
< Content-Type: text/html; charset=utf-8
< Content-Length: 4
< Server: Werkzeug/0.10.4 Python/2.7.8
< Date: Sun, 22 Aug 2021 08:01:50 GMT
<
* Closing connection 0
post
$curl 'http://127.0.0.1:5028/test' -H 'Content-Type:application/json' -d '{"action":"post"}' -v
* About to connect() to 127.0.0.1 port 5028 (#0)
*   Trying 127.0.0.1...
* Connected to 127.0.0.1 (127.0.0.1) port 5028 (#0)
> POST /test HTTP/1.1
> User-Agent: curl/7.29.0
> Host: 127.0.0.1:5028
> Accept: */*
> Content-Type:application/json
> Content-Length: 17
>
* upload completely sent off: 17 out of 17 bytes
* HTTP 1.0, assume close after body
< HTTP/1.0 200 OK
< Content-Type: text/html; charset=utf-8
< Content-Length: 4
< Server: Werkzeug/0.10.4 Python/2.7.8
< Date: Sun, 22 Aug 2021 07:52:42 GMT
<
* Closing connection 0
post
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值