使用curl发送HTTP请求,用于简单验证接口连接性。

GET 请求示例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# GET请求 -i
curl -i <url>
# 返回示例:
# HTTP/1.0 200 OK
# Content-Type: application/json
# Content-Length: 151
# Server: Werkzeug/0.8.3 Python/2.7.3
# Date: Mon, 20 May 2013 05:21:50 GMT
#
# {
# "data": {
# "description": "Need to find a good Python tutorial on the web",
# },
# "code": 200
# }

POST 请求示例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
# POST请求示例 -i
curl -i -H "Content-Type: application/json" -X POST -d '{"data":"data"}' <url>
# HTTP/1.0 201 Created
# Content-Type: application/json
# Content-Length: 104
# Server: Werkzeug/0.8.3 Python/2.7.3
# Date: Mon, 20 May 2013 05:56:21 GMT
#
# {
# "data": {
# "description": "Need to find a good Python tutorial on the web",
# },
# "code": 200
# }

curl 带密码请求

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# -u username:password -i url
curl -u miguel:python -i <url>

# HTTP/1.0 200 OK
# Content-Type: application/json
# Content-Length: 316
# Server: Werkzeug/0.8.3 Python/2.7.3
# Date: Mon, 20 May 2013 06:46:45 GMT
#
# {
# "data": {
# "description": "Need to find a good Python tutorial on the web",
# },
# "code": 200
# }



向博主反馈问题