>  기사  >  백엔드 개발  >  python client使用http post 到server端的代码

python client使用http post 到server端的代码

WBOY
WBOY원래의
2016-06-16 08:46:471027검색
复制代码 代码如下:

import urllib, httplib 
import utils 
import json
       class User: 

        def __init__(self): 
            print 'a' 

        def login(self, imsi, ua): 
            print "==============user start login==================" 
            input = { 
                "method"       : "user.login", 
                "userName"     : "", 
                "userPass"     : "", 
            } 

            input["sig"] = utils.getSignature(input) 
            params = urllib.urlencode(input) 
            headers = { 
                "user-agent"  : ua, 
                "Appstore-clientType" : "android", 
                "Appstore-IMEI" : "123456789000000", 
                "Appstore-IMSI" : imsi 
            } 

            try: 
                connection = httplib.HTTPConnection(utils.API_HOST) 
                connection.request("POST", "/api", params, headers) 
                response = connection.getresponse().read() 
                #print "=========" + response 
                connection.close() 
            except Exception, e : 
                print "========" + str(e)     

            if "errorcode" in response or response is None: 
                return 

            results = json.loads(response)     

            return results["results"].encode("utf-8")
성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.