码迷,mamicode.com
首页 > 编程语言 > 详细

pythonhttp

时间:2015-02-03 12:54:17      阅读:162      评论:0      收藏:0      [点我收藏+]

标签:

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‘},
        data    = data)

ret = opener.open(request)
content = ret.read() 
print content

pythonhttp

标签:

原文地址:http://www.cnblogs.com/wcLT/p/4269534.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!