最新消息: 电脑我帮您提供丰富的电脑知识,编程学习,软件下载,win7系统下载。

OPTIONS net :: ERR

IT培训 admin 5浏览 0评论

OPTIONS net :: ERR

我尝试在我的服务器上部署一个React / Node项目。当我发出axios请求(例如,单击“题词”)时,我的浏览器中显示了该应用程序,但服务器发生超时错误

在我的中间件中:

axios.post(':3000/inscription', data)

server.js:

app.use(function(req, res, next) {
  res.header('Access-Control-Allow-Origin', '');
  res.header('Access-Control-Allow-Credentials', true);
  res.header('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept');
  res.header('Access-Control-Allow-Methods', 'GET, POST');
  next();
});
...
app.post("/inscription", (req, res) => {
...

控制台错误:选项:3000/inscription net :: ERR_CONNECTION_TIMED_OUT

回答如下:

尝试使用此配置:

  //add the port config 
  res.header('Access-Control-Allow-Origin', 'https://www.mySite.top:3000');
  res.header('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept');
  res.header('Access-Control-Allow-Methods', 'GET, POST');

还要检查服务器是否已启动。

OPTIONS net :: ERR

我尝试在我的服务器上部署一个React / Node项目。当我发出axios请求(例如,单击“题词”)时,我的浏览器中显示了该应用程序,但服务器发生超时错误

在我的中间件中:

axios.post(':3000/inscription', data)

server.js:

app.use(function(req, res, next) {
  res.header('Access-Control-Allow-Origin', '');
  res.header('Access-Control-Allow-Credentials', true);
  res.header('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept');
  res.header('Access-Control-Allow-Methods', 'GET, POST');
  next();
});
...
app.post("/inscription", (req, res) => {
...

控制台错误:选项:3000/inscription net :: ERR_CONNECTION_TIMED_OUT

回答如下:

尝试使用此配置:

  //add the port config 
  res.header('Access-Control-Allow-Origin', 'https://www.mySite.top:3000');
  res.header('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept');
  res.header('Access-Control-Allow-Methods', 'GET, POST');

还要检查服务器是否已启动。

与本文相关的文章

发布评论

评论列表 (0)

  1. 暂无评论