Thursday, 2 October 2014

Python urllib2 post request

We can post a request through urllib with parameter. we can also encode a dict using urllib like this:

See below code :
import urllib
import urllib2

url = 'http://example.com/...'
values = { 'productslug': 'bar','qty': 'bar' }
data = urllib.urlencode(values)
req = urllib2.Request(url, data)
response = urllib2.urlopen(req)
result = response.read()
print result


You can encode value through urlencode and send it securely by requested url.  you can also send data without encryption. It will execute url request and return response.


Hi Guys if these all post are helpful for you then please follow my blog through google plus or facebook, I will share other useful post for you . If you have any suggestion for me please share to me.

Thanks guys for your support.

No comments:

Post a Comment