问题具体如下:
Failed to execute ‘fetch’ on ‘Window’: Failed to read the ‘headers’ property from ‘RequestInit’: String contains non ISO-8859-1 code point.
该问题的出现代表请求中的headers出现了格式问题,导致不符合HTTP规范。如果使用了非ISO-8859-1字符,必须进行编码,这里使用encodeURIComponent()进行编码转义。
举一个例子,如下图:
在Request Headers
中添加 X-Cluster,但是它的值配置中出现中文,如果不做编码转义处理,此时就会报上面的错误。
解决办法:
const val = '你好-Hello-2023-11'
headers['X-Cluster'] = encodeURIComponent(value);