Reputation: 3
I am trying to send a post request (that contains specific parameters and values) to a php server (that is instructed to check if the specified request has certain parameters and in that case it will save the values into a database).
With the following curl command i am successfully able to register the request into the server database:
sudo curl -d 'hostname=RegisterTest&ip=127.0.0.1&operatingsystem=testOpsys' -X POST http://localhost/register.php
This is also the curl command that i am trying to simulate with a python script. The problem is that i have tried various python syntaxes but i couldn't replicate the curl command and even if the request is sent (and server response is received) the registration will not take place .
import requests
url = “http://localhost/register.php”
data = {'hostname=RegisterTest&ip=127.0.0.1&operatingsystem=testOpsys'}
response = requests.post(url, data=data)
print(response)
Upvotes: 0
Views: 26
Reputation: 1148
You need to format the data as a dictionary.
import requests
data = {
'hostname': 'RegisterTest',
'ip': '127.0.0.1',
'operatingsystem': 'testOpsys'
}
response = requests.post('http://localhost/register.php', data=data)
Upvotes: 1