node.js - 带有 UTF-8 的 axios setRequestHeader 方法
问题描述
我正在尝试在我的请求中添加一些标头。但是标头值可能包含一些土耳其语字符(如 ğ、ş、ö 等),当我尝试这样做时,我得到了这个错误:
TypeError: Failed to execute 'setRequestHeader' on 'XMLHttpRequest': String contains non ISO-8859-1 code point.
at setRequestHeader (xhr.js:132)
at Object.forEach (utils.js:253)
at dispatchXhrRequest (xhr.js:126)
at new Promise (<anonymous>)
at xhrAdapter (xhr.js:13)
at dispatchRequest (dispatchRequest.js:52)
at :3000/report/async http:/localhost:3000/static/js/main.chunk.js:4137
我猜 axios 在将我的自定义标题添加到标题列表时支持 ISO-8859-1 字符。是否可以将 axios 支持的字符集更改为 UTF-8?
解决方案
让 headers = {"userId": user.id, "username":user.username, "relatedName": encodeURIComponent(values.username) }; 在 React 上编码。relatedName = URLDecoder.decode(request.getHeader("relatedName"), StandardCharsets.UTF_8.name()); 在 Java 中解码。
推荐阅读
- apache-nifi - Apache NiFi EvaluateJson 路径以 $(美元符号)开头
- javascript - 当militaryHour变量设置为0时,为什么系统打印0而不是我设置的小时(变量)是12?
- c# - 如何使用 JsonExtensionData 反序列化对象,使用 JsonProperty 序列化对象
- java - 我很难确定 LoopWhileDO 的作用范围
- javascript - 登录到不使用 POST 请求的网站 - 使用 Python 进行网络抓取
- java - 迭代表行并单击行内的按钮/链接
- javascript - 谷歌地图根据 xml 值更改标记颜色
- android - 单击后抽屉导航标题按钮不起作用
- javascript - 使用 apply() 与 new Array 构造数组
- c++ - this->field 与 C++ 中的 this.field