我正在嘗試在 React 中向服務器發出發布請求
我的 React 應用程式在埠 3000 上運行,而 express 應用程式在埠 9000 上運行
反應:
axios.post("/").then((response)=>{
console.log(response.data)
}).catch((e)=>{
console.log(e.response.data)
this.out = e.response.data
})
表達:
app.post("/", (req, res) => {
console.clear()
console.log(req.body)
res.end("req")
})
在網路控制臺上它說:“無法加載資源:服務器回應狀態為 404(未找到)”
在應用程式“郵遞員”上它運行得很好
我試著按照這個 YT 教程https://www.youtube.com/watch?v=kJA9rDX7azM
uj5u.com熱心網友回復:
首先,您需要檢查是否在您的 React APP 專案 Package.Json 檔案中的私有依賴項名稱 proxy 下添加代理:
'http://localhost:9000/'
Axios 首先在當前服務器中查找您請求的埠,在您的情況下是 / so / 也是前端的埠,因此后端永遠不會安全使用
axios.post("http://localhost:9000/")
.then((response)=>{
console.log(response.data)
})
.catch((e)=>{
console.log(e.response.data)
})
其次確保你必須在你的反應專案中安裝 axios 依賴項
uj5u.com熱心網友回復:
好像您忘記在 axios 請求中添加域。
axios.post("http://localhost:9000/").then((response)=>{
console.log(response.data)
}).catch((e)=>{
console.log(e.response.data)
this.out = e.response.data
})
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/534596.html
標籤:节点.js反应表示
