dreamhead / moco

Easy Setup Stub Server
MIT License
4.35k stars 1.08k forks source link

响应体中存在奇数个汉字的时候必定乱码 #329

Open yifei325325 opened 1 year ago

yifei325325 commented 1 year ago

响应体如下:

[
    {
        "description": "模拟一个基本的 RESTful API",
        "request":
        {
            "uri": "/hello"
        },
        "response":
        {
            "headers":
            {
                "Content-Type": "application/json; charset=utf-8",
                "Access-Control-Allow-Origin": "*",
                "Access-Control-Expose-Headers": "X-Requested-With",
                "Access-Control-Allow-Methods": "GET,POST,OPTIONS"
            },
            "json":
            {
                "result":
                [
                    {
                        "name": "字",
                        "age": 18
                    },
                    {
                        "name": "两字",
                        "age": 18
                    },
                    {
                        "name": "三个字",
                        "age": 18
                    },
                    {
                        "name": "四个字字",
                        "age": 18
                    },
                    {
                        "name": "有五个字字",
                        "age": 188
                    }
                ]
            }
        }
    }
]

显示结果如下: image 希望开发者有空修复一下,不胜感激!

dreamhead commented 1 year ago

I've tested this configuration with moco 1.4.0 release on Mac and it works well. I guess your editor does not save this configuration in correct charset.

yifei325325 commented 1 year ago

Hi Dreamhead,

Thanks for your quick response. I tried the MacBook with moco 1.4.0. Yes, It exactly works, But for the Windows PC, It's not. Can I trouble you to debug this on a Windows PC? (Windows 10 22H2 installed). Thank you very much.

yifei325325 commented 1 year ago

The sublime encode is UTF-8 which is the same as MacBook did. image

yifei325325 commented 1 year ago

The console log is below:

GET /hello HTTP/1.1
Cookie: Pycharm-1ff3c3be=71f9c357-d755-4f06-bb6c-4f940f546c29; Webstorm-c182b445=39a3fd0f-e14c-4fd4-beff-363155306b08; ___rl__test__cookies=1683883019300
content-length: 0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9
Connection: keep-alive
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.4577.63 Safari/537.36
Sec-Fetch-Site: none
Sec-Fetch-Dest: document
Host: localhost:9999
Accept-Encoding: gzip, deflate
Sec-Fetch-Mode: navigate
sec-ch-ua: "Google Chrome";v="93", " Not;A Brand";v="99", "Chromium";v="93"
sec-ch-ua-mobile: ?0
Upgrade-Insecure-Requests: 1
sec-ch-ua-platform: "Windows"
Sec-Fetch-User: ?1
Accept-Language: zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7,ko-KR;q=0.6,ko;q=0.5,de-DE;q=0.4,de;q=0.3,zh-HK;q=0.2

15 May 2023 08:52:16 [pool-1-thread-4] INFO  Response return:

HTTP/1.1 200
Access-Control-Expose-Headers: X-Requested-With
Access-Control-Allow-Origin: *
Access-Control-Allow-Methods: GET,POST,OPTIONS
Content-Length: 163
Content-Type: application/json; charset=utf-8

{"result":[{"name":"瀛?","age":18},{"name":"涓ゅ瓧","age":18},{"name":"涓変釜瀛?","age":18},{"name":"鍥涗釜瀛楀瓧","age":18},{"name":"鏈変簲涓瓧瀛?","age":188}]}
HelloEason commented 1 year ago

i have meet the same problem while response xml body . fix that via move the data into file as the api says, but by this way , it can't support template image