我很好奇Python requests.post(JSON格式)以及如何从PHP服务器获取POST

3qpi33ja  于 11个月前  发布在  Python
关注(0)|答案(1)|浏览(90)

python代码

import json
import requests

temp_dict = {"user_id":"zed","user_password":"zed123","degrees":"23.5"}

r=requests.post('https://localhost:8080/php/test.php',json = temp_dict)
print(r.status_code)

字符串
php代码

<?php
    echo json_decode(file_Get_contents("php://input"))->{'user_id'};
?>


我想把Python发送的字典的键和值以echo的形式导出,但是我不知道怎么做。
运行.py文件后的status_code结果:200运行.py文件后的文本结果:空值

6jygbczu

6jygbczu1#

<?php

http_response_code(200);

$input = json_decode(file_get_contents("php://input"), true);
echo $input["user_id"];

字符串

相关问题