简体   繁体   中英

How to do a Post Request in Python?

Hi I'm sitting in a Greyhound Bus with Wifi and want to connect a second Device to the Network. But I have to accept an onscreen contract and the device does not have a browser. To accept the contract the following form has to be accepted. The device has no CURL but all the standard python 2.6. libraries.

<form method="POST" name="wifi" id="wifi" action="http://192.168.100.1:5280/">  
  <input type="image" name="mode_login" value="Agree" src="btn_accept.gif" />  
  <input type="hidden" name="redirect" value="http://stackoverflow.com/">       
</form>

How would I write a quick python script to accept the contract?

I think this should do the trick:

import urllib
data = urllib.urlencode({"mode_login":"Agree","redirect":"http://stackoverflow.com"})
result = urllib.urlopen("http://192.168.100.1:5280/",data).read()
print result

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM