UnityWebRequest.Post 会使后端报出数据读取格式错误

最近在用unity和python做交互,发现了unity的一个坑:
unity使用post接口提交数据之后服务器发现会出现错误的字符,中文更不行了,奇怪了很久很久,不得琪姐。
b’This is \xe6\x88\x91\xe6\x9d\xa5\xe5\x8f\x91\xe4\xb8\x80\xe4\xba\x9b\xe4\xb8\xad\xe6\x96\x87\xe8\xaf\x95\xe8\xaf\x95\xe8\xa1\x8c\xe4\xb8\x8d\xe8\xa1\x8csome test data’

客户端 代码示意:
UnityWebRequest www = UnityWebRequest.Post(“http://127.0.0.1:8888”, “This is 我来发一些文试试行不行some test data”));
yield return www.SendWebRequest();

服务端代码示意

from http.server import HTTPServer, BaseHTTPRequestHandler
import json
import time

data = {‘result’: ‘this is a test’}
host = (‘localhost’, 8888)

class Resquest(BaseHTTPRequestHandler):
def do_GET(self):
self.send_response(200)
self.send_header(‘Content-type’, ‘application/json’)
self.end_headers()
self.wfile.write(json.dumps(data).encode())

def do_POST(self):
    datas = self.rfile.read(in
  • 6
    点赞
  • 19
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值