Quantcast
Channel: CSDN博客推荐文章
Viewing all articles
Browse latest Browse all 35570

python client使用 http post 到server端

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

作者:androidzhaoxiaogang 发表于2012-12-31 23:52:58 原文链接
阅读:54 评论:0 查看评论

Viewing all articles
Browse latest Browse all 35570

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>