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.

image

url = 'http://www.yoursite.com/pagetotest.php'

The syntax of the post parameters works in this way:

values = {'name of the post' : 'value of the post'}

For example if you want to send a post called username that has as value Andrea you have to set:

values = {'username' : 'Andrea'}

You can send simultaneously more parameters, just separate them with a comma:

values = {'username' : 'Andrea', 'password' : 'cmprogrammers'}

There are a lot of ways to run our script. We are using Arch Linux as OS so we run:

sudo python2 post.py

In this case we are testing a login procedure and we get the response directly from the PHP script.

image image

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 urllib import urllib2
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