How can I post data to php and print that data?

411 Views Asked by At

I tried requests module but I've error in my php outputs: The error is: Notice: Undefined index: firstname in D:\xampp\htdocs\myfile\receive.php on line 7 NULL

code in python:
'''
payload = {'firstname':'Jack'}
url = "http://localhost/myfile/receive.php"
resp = requests.post(url, data=payload)
print(resp.status_code)
text =resp.text
print(text)
'''
status_code is ok(200)!

php code:
$data = $_POST["firstname"];
var_dump($data);

It seems okay but it's not :)

1

There are 1 best solutions below

0
Marco On

In your php code, you have to use $_REQUEST["firstname"];

$data = $_REQUEST["firstname"]

instead of using $_POST