[英]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.