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")
上一篇: Excel文件读取的两种方式
下一篇: 让你成为设计大师的20个设计法则