Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Request请求:Failed to execute 'setRequestHeader' on 'XMLHttpRequest': String contains non ISO-8859-1 code point. #73

Open
george-es opened this issue Dec 3, 2020 · 0 comments
Labels

Comments

@george-es
Copy link
Owner

问题:

Uncaught (in promise) TypeError: Failed to execute 'setRequestHeader' on 'XMLHttpRequest': String contains non ISO-8859-1 code point.

问题定位:
上传文件名为中文时报错

类型错误:未能在“XMLHttpRequest”上执行“setRequestHeader”:字符串包含非ISO-8859-1代码点。

image

问题分析:

初步怀疑是中文名导致的,在前端页面发送request请求到后台时,请求头即 header 中放入了中文,所以就会出现编码格式问题。

代码速览:
文件上传功能,调用 ali-oss 的 put 方法上传文件,在 meta 中设置 filename
image

解决方案
要解决问题就要对中文字符进行编码,到后台里再进行解码接收处理。
image

image

// 编码
encodeURIComponent(str)
// 解码
decodeURIComponent(str)
@george-es george-es added the node label Dec 3, 2020
@george-es george-es changed the title Request请求:Failed to execute 'setRequestHeader' on 'XMLHttpRequest': String contains non ISO-8859-1 code point.问题解决 Request请求:Failed to execute 'setRequestHeader' on 'XMLHttpRequest': String contains non ISO-8859-1 code point. Dec 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant