赞
踩
问题:
一开始没写try catch,报错如下:
[UnhandledPromiseRejection: This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). The promise rejected with the reason "#<Err>".] {
code: 'ERR_UNHANDLED_REJECTION'
}
经过我一部分一部分的注释代码调试,终于发现出问题的地方在哪了。
加上try catch后,打印出具体错误:
Request path contains unescaped characters这个错误翻译过来就是 “请求路径包含未转义字符” ,因为我的请求路径含有中文。
解决方法:encodeURI(‘处理的变量’);
例:let url = `http://localhost:3000/.....?cat=${encodeURI('欧美')}......`
参考文章:轻松决绝疑难杂症:nodejs使用http报错: Request path contains unescaped characters_大雄Obear的博客-CSDN博客
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。