关于前端请求URL报错
来源:8-1 完成基本的文件上传功能

慕仙3318693
2020-07-05
上传文件请求后端url,自己排查了好几遍,也百度了可还是找不到原因,报错如下
xhr.js?b50d:178 POST http://127.0.0.1:9000/file/admin/upload 404 (Not Found)
dispatchXhrRequest @ xhr.js?b50d:178
xhrAdapter @ xhr.js?b50d:12
dispatchRequest @ dispatchRequest.js?5270:52
Promise.then (async)
request @ Axios.js?0a06:61
Axios. @ Axios.js?0a06:86
wrap @ bind.js?1d2b:9
uploadImage @ teacher.vue?174d:226
change @ teacher.vue?6298:205
invokeWithErrorHandling @ vue.runtime.esm.js?2b0e:1854
invoker @ vue.runtime.esm.js?2b0e:2179
original._wrapper @ vue.runtime.esm.js?2b0e:6917
createError.js?2d83:16 Uncaught (in promise) Error: Request failed with status code 404
at createError (createError.js?2d83:16)
at settle (settle.js?467f:17)
at XMLHttpRequest.handleLoad (xhr.js?b50d:61)
代码定位:
uploadImage(){
let _this = this;
let formData = new window.FormData();
formData.append('file', document.querySelector('#file-upload-input').files[0]);
_this.$ajax.post(process.env.VUE_APP_SERVER + '/file/admin/upload',
formData, {
headers : {
'Content-Type': 'multipart/form-data'
},
}
).then((response)=>{
// console.log("保存结果:", response);
let resp = response.data;
let image = resp.content;
console("头像地址:", image);
_this.teacher.image = image;
});
// let instance = _this.$ajax.create({ headers: {'content-type': 'application/x-www-form-urlencoded'} });
// instance.post(process.env.VUE_APP_SERVER + '/file/admin/upload', formData)
// .then((response)=>{
// let resp = response.data;
// })
}
那个请求头部分我试过好几种也试过不写可就是不行报同样的错误,缓存我也清理过,头疼,辛苦老师指点迷津
1回答
-
甲蛙
2020-07-05
报错404:http://127.0.0.1:9000/file/admin/upload 404 (Not Found)
检查file模块,upload这个请求的路径是否正确
检查gateway模块,是否配置了file的路由转发
你可以先直接调用file模块,直接用9003端口,调试接口,通了后再改成9000,调试路由转发
10
相似问题