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

时间:2015-02-18 17:57:22

标签: 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']);

我收到此错误.. 注意:未定义的索引: C:\ xampp \ htdocs \ Python_ \ test.php 中的行 8

我在REST客户端上尝试过,代码在REST客户端显示名称,但在localhost上显示错误。

1 个答案:

答案 0 :(得分:3)

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