一、問題如下:
1、報錯信息:
Uncaught (in promise) TypeError: Failed to execute 'setRequestHeader' on 'XMLHttpRequest': String contains non ISO-8859-1 code point.
未捕獲(承諾中)TypeError:未能對“XMLHttpRequest”執(zhí)行“setRequestHeader”:字符串包含非ISO-8859-1代碼點。
2、截圖如下:
3、問題分析:
在前端頁面發(fā)送request請求到后臺時,請求頭即header中放入了中文,所以就會出現(xiàn)編碼格式問題。
4、問題解決:
要解決問題就要對中文字符進行編碼,到后臺里再進行解碼接收處理。
以下為vue中使用JS對中文進行編碼解碼的方式:
編碼
encodeURIComponent(String)
解碼
decodeURIComponent(String)
?后臺進行接收:
編碼
java.net.URLEncoder.encode(String,"UTF-8")
解碼文章來源:http://www.zghlxwxcb.cn/news/detail-854203.html
java.net.URLDecoder.decode(String,"UTF-8")
??文章來源地址http://www.zghlxwxcb.cn/news/detail-854203.html
到了這里,關(guān)于Failed to execute ‘setRequestHeader‘ on ‘XMLHttpRequest‘: String contains non ISO-8859-1 code point.的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!