前端如何将请求头中的中文编码转成UTF-8格式

先说一下我当时出现的问题,是在使用下载文件功能时,需要在headers[“content-disposition”]获取文件名称,但是取出来的时候是类似 %E4%BA%94%E6%A3%B5%E 这种格式,所以使用以下方式进行解码

服务器端:
String encodeStr = URLEncoder.encode(“下载”, “utf-8”);
System.out.println(“处理后:” + encodeStr);

//处理后:%E4%BA%94%E6%A3%B5%E

客户端:
String decodeStr = URLDecoder.decode(encodeStr, “utf-8”);
System.out.println(“解码:” + decodeStr);

//解码 下载

猜你喜欢

转载自blog.csdn.net/qq_39215166/article/details/120000377