Python 模拟 POST 请求发送 application/x-www-form-urlencoded 类型的表单数据 / 含重复键_分享是一种快乐-CSDN博客
需要注意:请求头 表单数据的提交类型为application/x-www-form-urlencoded,这时需要对data进行编码在发送;
示例
def post_xueqiu(content,__cookies,session_token):
url_post = "https://xueqiu.com/statuses/update.json"
params = {}
url = url_post+(urlencode(params))
payload={
'status':content,
'session_token':session_token
}
headers.update(
{
"Content-Type":"application/x-www-form-urlencoded; charset=UTF-8",
"Cookie":__cookies}
)
# 这里把doseq改为True;把每个序列元素转换为一个单独的参数
# data = urlencode(payload)
print("data-payload",urlencode(payload))
response = requests.request("POST", url, headers=headers, data=urlencode(payload))
data = response.json()
print(response.text)
return data
pass