[英]why the console is giving the error Bad request(400) when i am trying to fetch the backend function 'createOrder'?
我正在为支付网关使用braintree,当我使用他们给定的信用卡进行测试时,支付功能工作正常,但在支付后,当后端获取代码被命中但它不工作时,它应该创建一个订单。 我正在使用此代码来获取后端 function,
import { API } from "../../backend";
export const createOrder = (userId,token,orderData) => {
return fetch(`${API}/order/create/${userId}`, { //getting error at this line
method: "POST",
headers: {
Accept: "application/json",
"Content-Type": "application/json",
Authorization: `Bearer ${token}`
},
body: JSON.stringify({order: orderData})
}).then(response => {
return response.json();
}).catch(err => {
console.log(err);
})
};
后端代码是,
router.param("userId", getUserById);
router.post(
"/order/create/:userId",
isSignedIn,
isAuthenticated,
pushOrderInPurchaseList,
updateStock,
CreateOrder
);
我收到错误“错误请求”。 相同的获取请求正在其他地方工作,例如创建产品和类别,API 在那里工作正常,但在这里不行。
400 BAD REQUEST 的一些原因
URL 字符串语法错误。 HTTP 错误 400 可能是由于键入错误的 URL、语法错误或包含非法字符的 URL 造成的
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.