Python编程语言在实际应用中给开发人员带来了非常大的好处。我们可以先通过这篇文章中介绍的有关Python HTTP操作的相关内容对这一编程语言的应用方式有一个详细的了解,并增加对其的印象。
Python HTTP操作代码示例:
- import urllib2,cookielib
- class HTTPRefererProcessor(urllib2.BaseHandler):
- def __init__(self):
- self.referer = None
- def http_request(self, request):
- if ((self.referer is not None) and
- not request.has_header("Referer")):
- request.add_unredirected_header("Referer", self.referer)
- return request
- def http_response(self, request, response):
- self.referer = response.geturl()
- return response
- https_request = http_request
- https_response = http_response
- cj = cookielib.CookieJar()
- opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj),
HTTPRefererProcessor(),)- urllib2.install_opener(opener)
- data = 'msisdn=999999'
- request = urllib2.Request(
- url = 'http://203.117.16.171:8080/webgamecode/webcore?action=topup',
- headers = {'Content-Type': 'application/x-www-form-urlencoded'},
- datadata = data)
- ret = opener.open(request)
- content = ret.read()
- print content
以上就是我们对Python HTTP操作的相关介绍。
【编辑推荐】