前端报错:Failed to execute 'setRequestHeader' on 'XMLHttpRequest': Value is not a valid ByteString.

家住魔仙堡 提交于 2020-02-01 06:20:51

报错详细:

Unhandled Rejection (TypeError): Failed to execute 'setRequestHeader' on 'XMLHttpRequest': Value is not a valid ByteString.

报错原因:

       是请求头中存在汉字

解决方案:

       我们前段可以使用Base64进行编码 encodeURI() 这个函数,然后后端对这个Base64进行解码,具体函数如下:

 public String decode(String url) {
        String prevURL = "";
        String decodeURL = url;
        while (!prevURL.equals(decodeURL)) {
            prevURL = decodeURL;
            decodeURL = URLDecoder.decode(decodeURL, StandardCharsets.UTF_8);
        }
        return decodeURL;
    }

 

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!