4

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
7
  • Do you have a web server set up that's listening for requests to the PHP script (at localhost)? Commented Feb 18, 2015 at 17:59
  • 2
    Try print_r($_POST). It will show array( [name] => John). On second thought, it will not. You are using the HTTP PUT method. Try file_get_contents('php://input');. Commented Feb 18, 2015 at 18:02
  • It is post() .. my apology Commented Feb 18, 2015 at 18:05
  • @Jack Yes I do have localhost up & running. However it shows that undefined index while running at localhost. When I use REST Client, it works fine with it. Commented Feb 18, 2015 at 18:07
  • 1
    @Jack ,Boldewyn Thanks guys! The mistake I had made was ..I had to get $_POST['name'] & not $_POST['keys'] Commented Feb 18, 2015 at 18:24

1 Answer 1

3

Your post data will be the keys dictionary.
Your php code should be print_r($_POST['name']);

answered Jun 23, 2015 at 6:50
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.