2021更新:
# -*- coding:utf-8 -*-
import requests
import json
adata = {
"email":"hi"
}
aheaders = {'Content-Type': 'application/json'}
url = "http://localhost:5002/dada"
response = requests.post(url, headers=aheaders, data = json.dumps(adata))
print response.text
python post json 的一个例子,可用于验证后台 post 接口。
把代码拷贝到一个文件,如 py_post.py。
然后执行: python py_post.py
============
原文
# -*- coding:utf-8 -*-
import requests
import json
import sys
reload(sys)
sys.setdefaultencoding('utf-8')
adata = {
"email":"hi"
}
aheaders = {'Content-Type': 'application/json'}
url = "http://localhost:5002/dada"
response = requests.post(url, headers=aheaders, data = json.dumps(adata))
print response.text