102 Star 712 Fork 170

DtFlys / forest

使用post请求时,body里面发现中文乱码,Content-type 为 application/json;charset=utf-8,求大佬帮忙指点

Backlog
wangjl  Opened this issue

使用post请求时,body里面发现中文乱码,Content-type 为 application/json;charset=utf-8,求大佬帮忙指点

@Request(
        url = "${"+ForestApiConstant.GOODS_PUSH_KEY+"}?token=${token}",
        type = "post",
        charset = "utf-8",
        headers ={
                "Accept-Charset: utf-8",
                "Content-Type:application/json;charset=utf-8"
        },
        contentEncoding = "utf-8"
    )
1216742 dt flys 1594991700 total 2 participants

Comments (8)

1216742 dt flys 1594991700
DtFlys 2020-09-11 11:42 owner

body是怎么写的?乱码的结果是什么样子的?能否截图看一下

wangjl 2020-09-11 11:50
@Request(
        url = "${"+ForestApiConstant.GOODS_PUSH_KEY+"}?token=${token}",
//        url = "${url}?token=${token}",
        type = "post",
        charset = "utf-8",
        headers ={
                "Accept-Charset: utf-8",
                "Content-Type:application/json;charset=utf-8"
        },
        contentEncoding = "utf-8"
    )
    CommodityResult pushGoods(@DataObject OuyeelCommodityDTO param, @DataVariable("token")String token);

输入图片说明

1216742 dt flys 1594991700
DtFlys 2020-09-11 11:56 owner

forest版本号是多少?

wangjl 2020-09-11 12:01

输入图片说明
我在debug的时候看com.dtflys.forest.backend.okhttp3.body.AbstractOkHttp3BodyBuilder#setStringBody 里面传入的参数text还没乱码,创建okhttp3的RequestBody时也都指定为了utf-8,后面日志打印出body的时候就乱掉了
输入图片说明

1216742 dt flys 1594991700
DtFlys 2020-09-11 12:04 owner

是不是IDEA控制台编码显示的问题

1216742 dt flys 1594991700
DtFlys 2020-09-11 12:06 owner

输入图片说明

我这里看到是正常的

wangjl 2020-09-11 14:11

非常感谢回复,后来发现Http请求参数传递时中文并没有乱码,只是在日志输出的部分乱码了。。

com.dtflys.forest.backend.okhttp3.executor.AbstractOkHttp3Executor.class:156

这里新建数据流时,好像是因为没有指定编码导致日志输出中文乱码,
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream,:point_right:"utf-8"));
上面仅仅是我个人的观点,还需要大佬确认后进行定夺。

1216742 dt flys 1594991700
DtFlys 2020-09-11 17:09 owner

好的,日志的编码我会去看一下

Sign in to comment

Assignees
Labels
Not set
Projects
Milestones
Branches
Planed to start
Not set
Planed to end
Not set
Top level
Priority
Java
1
https://gitee.com/dt_flys/forest.git
git@gitee.com:dt_flys/forest.git
dt_flys
forest
forest

Search