欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

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

程序员文章站 2022-05-25 17:39:45
复制代码 代码如下:import urllib, httplib  import utils  import json   &nbs...
复制代码 代码如下:

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")