当我试图将我的redux(Redux thunk)项目与我的后端连接起来时,我遇到了问题。我试图将product_id和数量(Qty)发布到后端服务器。我用邮递员检查了服务器。它正常工作。但从正面看,我得到了这个"net::ERR_NAME_NOT_RESOLVED“错误。这里给出了错误消息:
我试图在我的cartActoin.js文件中发布axios。下面是该addCart的代码:
export const addCart = (product) => async (dispatch) => {
try {
const { id, title, price, category, image, rating, description, qty } = product;
const newProduct = {
"productId": id,
"qty": 1
}
// console.log("new", newProduct);
let axiosConfig = {
method: "POST",
headers: {
"Content-Type": "application/json",
"Access-Control-Allow-Origin": "*",
},
body: JSON.stringify(newProduct),
};
await axios.post("http://loclhost:5001/cartdata", newProduct, axiosConfig).then(()=>{
dispatch({
type: ActionTypes.ADD_CART,
payload: product,
})
}).catch((err) => {
console.log(err);
});
} catch (error) {
console.log(error)
}
}
我怎么能解决这个问题?谢谢。
发布于 2022-08-27 15:24:21
在发出“POST”请求时,您在URL中错误拼写了“localhost”关键字。
您的URL:'http://loclhost:5001/cartdata‘
https://stackoverflow.com/questions/73512224
复制相似问题