- 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
- 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