GET
#!/usr/bin/env python # encoding: utf-8 import urllib import urllib2 url = "http://127.0.0.1/index.php?a=hello world" request = urllib2.Request(url=url) response =urllib2.urlopen(request,timeout=20) result = unicode(response.read()) print result
POST
# encoding: utf-8 import urllib import urllib2 url = "http://127.0.0.1/index.php" par = urllib.urlencode({‘a‘:1}) request = urllib2.Request(url) opneer = urllib2.build_opener(urllib2.HTTPCookieProcessor())#所必须的 response = opneer.open(request,par) result = response.read() print result
时间: 2024-10-12 06:53:34