【问题标题】:http request with wrong domain域名错误的http请求
【发布时间】:2019-10-31 23:58:27
【问题描述】:

我在 axios 中使用从我的 React JS 前端到我的 Node JS 后端服务器的发布请求。

我的前端在 localhost:3000 上运行,而我的后端在 localhost:8080 上运行。

我的前端代码:

    foo = async () => {

    const data = {
        "data": "data",
    };

    const response = await axios.post('http:localhost:8080/createUser',data);
    console.log(response);
};

我的后端代码:

app.post("/createStripeConnectedAccount", async function (req, res) {

 const data = req.body;    
 // do some login here
 res('1')

});

但我在前端收到此错误:

xhr.js:166 POST http://localhost:3000/localhost:8080/createStripeConnectedAccount 404 (Not Found)

由于某种原因,post 请求同时发送到两个域。

【问题讨论】:

  • 其实是错字,http://不是http
  • http:localhost:8080/createUser

标签: node.js reactjs axios


【解决方案1】:

您的网址中有错字。而不是:

const response = await axios.post('http:localhost:8080/createUser',data);

应该是:

const response = await axios.post('http://localhost:8080/createUser',data);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-05-10
    • 2012-06-29
    • 2016-09-20
    • 2017-05-23
    • 1970-01-01
    • 2021-11-26
    • 1970-01-01
    • 2015-04-10
    相关资源
    最近更新 更多