python - 如何将数据从 python 传递到 php?

标签 python

我试过这段代码(Python 端)...

import requests
import json

keys = {"name": "John"}
headers = {'Content-type': 'application/x-www-form-urlencoded', 'Accept': 'text/plain'}

r = requests.post("http://localhost/Python_/test.php", data = keys, headers = headers)

print r.url
print r.status_code

在 php 方面,我正在尝试获取名称..

print_r($_POST['keys']);

我收到这个错误.. 注意:8

C:\xampp\htdocs\Python_\test.php 中的未定义索引:键>

我在 REST 客户端上试过了,代码在 REST 客户端上显示了名称,但在本地主机上出现了这个错误。

最佳答案

您的帖子数据将是 keys 字典。
你的 php 代码应该是 print_r($_POST['name']);

关于python - 如何将数据从 python 传递到 php?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28590542/

相关文章:

python - 从 dask 分布式线程池中分离任务

python - 如何使用 Django Rest Framework 将数据添加到 ManyToMany 字段?

python - 在 Cython 中创建对象列表

python - 显示另一列,其中条件在其他列中确定

python - 使用随机森林预测 future 发生的情况

python - scipy PchipInterpolator 错误 : 'array cannot be safely cast to required type'

python - python中将一个列表中的每个相同元素分配给另一个列表上的相同索引的最佳方法是什么?

python - 黑色不支持 "Format Selection"命令 - VS Code 错误

python - 如何使用 Python 请求检索前 10 个 Google 搜索结果

python - 从带有 'Show More' 按钮的网站上抓取信息