How to use python urllib2 to send json data for login

I want to use python urllib2 to simulate a login action, I use Fiddler to catch the packets and got that the login action is just an ajax request and the username and password is sent as json data, but I have no idea how to use urllib2 to send json data, help...

Answers


import urllib2
import json
# Whatever structure you need to send goes here:
jdata = json.dumps({"username":"...", "password":"..."})
urllib2.urlopen("http://www.example.com/", jdata)

This assumes you're using HTTP POST to send a simple json object with username and password.


Need Your Help

Remove test::unit

ruby-on-rails ruby-on-rails-3

I forgot to create my application with the -T argument and now it's installed with test::unit. How do I remove test::unit and stop it from creating tests for each controller / model generated, afte...

iPhone Application crashes in “AdHoc” mode

iphone objective-c cocoa-touch build-process

i got a little application which is working very well with my "debug" configuration on my phone and in simulator.