因为request库更常用,更想用这个,试了试,又能用了,看来真不能大半夜写东西,莫名其妙的错误不知道为啥。也懒得追究了,
下面是能用的代码
json_data = {
"phone": phone,
"password": password,
}
headers = {
"Content-Type": "application/x-www-form-urlencoded",
}
response = requests.post(url, json=json_data,headers=headers)
php代码接收:
if ($_SERVER['CONTENT_TYPE']!='application/x-www-form-urlencoded') {
return 0;
die;
}
$jsonData = file_get_contents('php://input');
$data = json_decode($jsonData, true);
var_dump($data);