python client使用http post 到server端的代码
程序员文章站
2023-02-22 23:10:46
复制代码 代码如下: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")
上一篇: Linux 安装CentOS7操作系统
下一篇: 记者招待会