'Setting PHP $_POST from Python [duplicate]
I would like to interact with a website written in PHP using Python. It pulls its data from a form with method `POST`. Now I have tried to set the values in `$_POST` by doing:
url = 'https://www.example.com/myscript.php'
data = {"PcID":"AJFJ-01AR","email":"email","refc":"","startBtn":"Start"}
result = requests.post(url, json=data).content
But I am sadly unable to set the values PHP receives with this (I am returned the page with form instead of after, meaning not all values are set). The data variable is copy-pasted from what PHP receives using the form on the website (echo json_encode($_POST);). Am I generally wrong in what I am doing? It wouldn't be hard for me to just give the values with a regular GET request but I am still wondering why this would not work.
Thank you!
Solution 1:[1]
The comment by deceze fixed it (thank you!). It should be result = requests.post(url, data=data).content not result = requests.post(url, json=data).content.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | OlMi1 |
