Open 18981119465 opened 7 years ago
Which version are you using?
Moco 0.11.1 has fixed a lot of encoding issues. I've tried your request in my local environment and it works well. Please ensure you are using the latest version.
If you want to show Chinese characters correctly, please setup Content-Type
with correct encoding, e.g
Content-Type: application/json;charset=UTF-8
中:如果是运行 moco-runner-standalone.jar,除了配置文件里要在 content-type 指定 charset 为 utf-8 外,还要在运行 moco-runner-standalone.jar 的时候加上 -Dfile.encoding=UTF-8
。即把 https://github.com/dreamhead/moco/blob/master/moco-shell/moco#L126-L149 的 exec "$JAVACMD" -jar "$MOCO_STANDALONE" $*
修改为 exec "$JAVACMD" -Dfile.encoding=UTF-8 -jar "$MOCO_STANDALONE" $*
。
En: Besides specifying charset to utf-8 in your json configuration, you need also explicitly tell java to run moco-runner-standalone.jar in UTF-8. So use java -Dfile.encoding=UTF-8 -jar moco-runner.jar
instead of java -jar moco-runner.jar
.
@district10 Thank you for your further comment.
request body: { "a":"中文", "b":"b", "c":[ { "1":1, "2":2 } ] }
mockserver日志如下: POST /wptrobot/api/generateTestcases HTTP/1.1 Host: localhost:12306 Connection: keep-alive Content-Length: 74 Postman-Token: 58110351-9cfb-6246-5491-91ed44dd0305 Cache-Control: no-cache Origin: chrome-extension://fhbjgbiflinjbdggehcddcbncdddomop User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36 content-type: application/json Accept: / Accept-Encoding: gzip, deflate, br Accept-Language: zh-CN,zh;q=0.8
04 八月 2017 17:04:22 [nioEventLoopGroup-3-2] INFO Response return:
HTTP/1.1 400
经过查看代码,发现HttpDumpers.isText返回false,从而导致HttpDumpers.contentForDump()方法返回,难道是 com.google.common.net.MediaType包处理含中文的报文是有问题?