#复杂post请求
url = 'http://m.ctrip.com'
payload = {'some': 'data'}
r = requests.post(url, data=json.dumps(payload)) #如果传递的payload是string而不是dict,需要先调用dumps方法格式化一下
---------------------------------------------------------------------------------------------------------
# -*- coding:utf-8 -*-
import requests
import json
# 发送post请求
def post(url, headers, values):
try:
headers['Content-Type'] = "application/json; charset=utf-8"
response = requests.post(
url=url,
headers=headers,
data=json.dumps(values)
)
return json.loads(response.content)
except requests.exceptions.RequestException, e:
print('HTTP Request failed :', url, values)
print e