client.py 客户端:
# -*- coding: utf-8 -*-
import requests
import json
import base64
url = "http://134.17.1.68:8887/face"
image_path = "test.jpg"
if __name__ == "__main__":
with open(image_path, 'rb') as f:
encoded_image = base64.b64encode(f.read())
post_dict = {"image": encoded_image}
res = requests.put(url, data = json.dumps(post_dict))
result_dict = json.loads(res.content)
print(result_dict)
server.py 服务器端:
class MainHandler(tornado.web.RequestHandler):
def put(self):
info_dict = json.loads(self.request.body)
image_data = base64.b64decode(info_dict["image"])
jpg_as_np = np.frombuffer(image_data, dtype=np.uint8)
print(jpg_as_np.shape)
image_buffer = cv2.imdecode(image_data, flags=1)
print(image_buffer.shape)
cv2.imwrite("test.jpg", image_buffer)
dict = {"code": 1, "result": "abcdef", "msg":"sucess"}
self.finish(dict)