簡體   English   中英

http 請求域錯誤

[英]http request with wrong domain

我在 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)

出於某種原因,發布請求與兩個域一起發送。

您的 url 中有錯字。 代替:

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

它應該是:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM