我正在使用以下 axios 查询在我的 Node.js Express 服务器上发送图片:
axios.post(this.server + 'images',
formData, {
crossdomain: true,
headers: {
'Content-Type': 'multipart/form-data'
}
}
).then(function (result) {
console.log(result);
})
.catch(function (error) {
console.log(error);
});
Run Code Online (Sandbox Code Playgroud)
图片现在在服务器上,但是,请看一下我在 Firefox 控制台中看到的奇怪行为,它显示“网络错误”,而 Axios 正在接收 200 状态!:
POST http://localhost/images
[HTTP/1.1 200 OK 20ms]
Error: "Network Error"
createError createError.js:16
handleError xhr.js:81
Run Code Online (Sandbox Code Playgroud)
这是我的 node.js 后端 Cors 参数:
const cors = require("cors");
app.use(
require("cors")({
origin: function(origin, callback) {
callback(null, origin);
}
})
);
app.use(function(req, res, next) {
res.header("Access-Control-Allow-Origin", req.headers.origin); // update to match the …Run Code Online (Sandbox Code Playgroud)