简体   繁体   中英

Changing a get request to a post in python?

I have this-

en.wikipedia.org/w/api.php?action=login&lgname=user&lgpassword=password

But it doesn't work because it is a get request. What would the the post request version of this?

Cheers!

The variables for a POST request are in the HTTP headers, not in the URL. Check urllib .

edit: Try this (i got it from here ):

import urllib
import urllib2

url = 'en.wikipedia.org/w/api.php'
values = {'action' : 'login',
          'lgname' : 'user',
          'password' : 'password' }

data = urllib.urlencode(values)
req = urllib2.Request(url, data)
response = urllib2.urlopen(req)
the_page = response.read()
params = urllib.urlencode({'action' : 'login', 'lgname' : 'user', 'lgpassword' : 'password'})
response = urllib.urlopen("http://en.wikipedia.org/w/api.php", params)

info about urllib can be found here .

由于您的示例在PHP中,因此请使用$ _REQUEST,它包含$ _GET和$ _POST的内容。

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