Send POST request with python using urllib2

Source code:

import httplib
import urllib
import urllib2

urllib2.install_opener(
    urllib2.build_opener(
        urllib2.ProxyHandler({'http': '127.0.0.1:8080'})
    )
)

headers = {
    #'Host': 'host.com',
    #'Connection': 'keep-alive',
    #'Content-Length': '325', 
    #'Origin': 'https://digitalvita.pitt.edu',
    #'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_4) AppleWebKit/537.1 (KHTML, like Gecko) Chrome/21.0.1180.89 Safari/537.1',
    'Content-type': 'application/x-www-form-urlencoded; charset=UTF-8',
    #'Accept': 'text/javascript, text/html, application/xml, text/xml, */*',
    #'Referer': 'https://digitalvita.pitt.edu/index.php',
    #'Accept-Encoding': 'gzip,deflate,sdch',
    #'Accept-Language': 'en-US,en;q=0.8',
    #'Accept-Charset': 'ISO-8859-1,utf-8;q=0.7,*;q=0.3',
    #'Cookie': 'PHPSESSID=lvetilatpgs9okgrntk1nvn595'
}

data = urllib.urlencode({
    "username":"admin",
    "password":"admin"})
req = urllib2.Request('http://abc.def/path', data, headers)
response = urllib2.urlopen(req)
print response.read()



Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s