Python2.7
页面地址:测试页面
import urllib
import urllib2
import cookielib
cooker = cookielib.CookieJar()
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cooker))
opener.addheaders = [('User-agent','Mzilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)')]
urllib2.install_opener(opener)
url = 'http://windroid.kuphp.net/Python-post-text/welcome.php'
qst = {'name':'Python-post-text','password':'text-password'}
request = urllib2.Request(url,urllib.urlencode(qst))
result = urllib2.urlopen(request)
html = result.read()
print html
#注意这里提交的地址不是index.php而是welcome.php
welcome.php
<html>
<body>
Welcome <?php echo $_POST['name']; ?><br>
Your password is: <?php echo $_POST['password']; ?>
</body>
</html>