- 安装
pip install httpie
- 测试get请求,这里我测试的是自己本地的服务器运行的页面,终端命令如下:
http http://127.0.0.1:8000/snippets/
获取的结果如下:
HTTP/1.0 200 OK
Content-Type: application/json
Date: Tue, 30 Jan 2018 08:14:12 GMT
Server: WSGIServer/0.2 CPython/3.6.2
X-Frame-Options: SAMEORIGIN
[
{
"code": "hello",
"id": 1,
"language": "python",
"linenos": false,
"style": "friendly",
"title": ""
},
{
"code": "say lalalala",
"id": 2,
"language": "python",
"linenos": false,
"style": "friendly",
"title": ""
},
{
"code": "say lalalala",
"id": 3,
"language": "python",
"linenos": false,
"style": "friendly",
"title": ""
}
]
- 测试post请求,因为是post,所以需要
http post + 地址 + @json地址
,json地址其实就是一个json文件,里面存储的是json数据,直接用自己本地的json文件的路径就可以了。
http POST http://127.0.0.1:8000/snippets/ @F:\qianfeng\python36_3\day12\snippets\snippetsapp\text.json
返回结果如下(我的json文件里的数据只写了一条):
HTTP/1.0 201 Created
Content-Type: application/json
Date: Tue, 30 Jan 2018 08:33:11 GMT
Server: WSGIServer/0.2 CPython/3.6.2
X-Frame-Options: SAMEORIGIN
{
"code": "nian a nian",
"id": 4,
"language": "python",
"linenos": false,
"style": "friendly",
"title": ""
}
这时候去数据库刷新一下,可以看到数据已经被提交过去了。