import hashlib
import tornado
import tornado.httpclient
import tornado.gen
token = '654321'
appsecret = 'B450744A16159A1F8B8201B394F2EA42'
appkey = '3B815C7FC3A568CCB26AA2937C915EF0'
password = hashlib.sha1((token + appsecret).encode()).hexdigest()
url = "http://192.168.1.201:7000/v1/app_data/data1000000030563792"
# 异步获取
@tornado.gen.coroutine
def AsyncTest():
print("This is post")
print(response.body)
# 同步获取
def test():
http_client = tornado.httpclient.HTTPClient()
response = http_client.fetch(url, method='GET', auth_username=appkey, auth_password=password)
print(response.body)
import tornado
import tornado.httpclient
import tornado.gen
token = '654321'
appsecret = 'B450744A16159A1F8B8201B394F2EA42'
appkey = '3B815C7FC3A568CCB26AA2937C915EF0'
password = hashlib.sha1((token + appsecret).encode()).hexdigest()
url = "http://192.168.1.201:7000/v1/app_data/data1000000030563792"
# 异步获取
@tornado.gen.coroutine
def AsyncTest():
print("This is post")
http = tornado.httpclient.AsyncHTTPClient()
# auth_username和auth_password发送到对发为headers中的以下内容
# Authorization: Basic base64_auth_string; base64_auth_string = base64(appkey:sha1(token+appsecret))
response = yield tornado.gen.Task(http.fetch, url, method='GET', auth_username=appkey, auth_password=password)print(response.body)
# 同步获取
def test():
http_client = tornado.httpclient.HTTPClient()
response = http_client.fetch(url, method='GET', auth_username=appkey, auth_password=password)
print(response.body)