In this article we are going to present a simple Python script that allow you to send post parameter. Through this useful software you can test your script, for example we use it to check if our PHP and Android scripts work.
Script
The script is real simple, you only have to set up the url of the page you want to test and the parameters you want to submit.
The syntax of the post parameters works in this way:
For example if you want to send a post called username that has as value Andrea you have to set:
You can send simultaneously more parameters, just separate them with a comma:
There are a lot of ways to run our script. We are using Arch Linux as OS so we run:
In this case we are testing a login procedure and we get the response directly from the PHP script.
Download
As usual our code is free and open-source. You can download the script directly from here or just copy and paste, but please pay attention to the indent.
import json
import time
from pprint import pprint
print "Connecting to the server..."
time.sleep(1)
url = 'http://www.cmprogrammers.com/script/login.php'
values = {'username' : 'A3ndrea', 'password' : 'cmprogrammers'}
data = urllib.urlencode(values)
req = urllib2.Request(url, data)
response = urllib2.urlopen(req)
page = response.read()
print page