I have tried this code(Python side)...
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
On php side, I am trying to get the name..
print_r($_POST['keys']);
And I am getting this error..
Notice: Undefined index: keys in C:\xampp\htdocs\Python_\test.php on line 8
I tried it on REST client, the code shows the name on REST client but on localhost it got this error.
asked Feb 18, 2015 at 17:57
Nevermore
8823 gold badges19 silver badges44 bronze badges
1 Answer 1
Your post data will be the keys dictionary.
Your php code should be print_r($_POST['name']);
answered Jun 23, 2015 at 6:50
Yash Mehrotra
3,1601 gold badge23 silver badges24 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
lang-py
print_r($_POST). It will showarray( [name] => John). On second thought, it will not. You are using the HTTPPUTmethod. Tryfile_get_contents('php://input');.