[英]unable to get request body in postman
我有一個 controller function 和一個端點:
controller
uploadSalesOrderFromExcel : async function (req,res) {
console.log(req.body);
if (!req.body.branchId) {
return res.status(400).send({ Error: "Branch Id is required." });
}
if (!req.file) {
return res.status(400).send({ Error: "Excel file is required." });
}
const excelData = await readExcel(file, { sheet: 'Sales Order' })
res.send(excelData);
}
路線http://localhost:8080/sp/salesOrders/uploadSalesOrder
現在,在從 postman 擊中 API 后,我得到了以下響應:
{
"Error": "Branch Id is required."
}
cURL
curl -X POST \
http://localhost:8080/sp/salesOrders/uploadSalesOrder \
-H 'Accept: */*' \
-H 'Accept-Encoding: gzip, deflate' \
-H 'Authorization: Basic Mzo5MTQ4MDk0ZjIxMDJhM2Q3M2U0OWY5NDljMGQ2YTIzYw==' \
-H 'Cache-Control: no-cache' \
-H 'Connection: keep-alive' \
-H 'Content-Length: 164' \
-H 'Content-Type: application/x-www-form-urlencoded' \
-H 'Host: localhost:8080' \
-H 'Postman-Token: 6bd29ccf-ebad-4299-8687-9ea46cf35686,4ea8d417-df27-49a1-8d84-3aabddbccd2c' \
-H 'User-Agent: PostmanRuntime/7.19.0' \
-H 'cache-control: no-cache' \
-H 'content-type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW' \
-F branchId=5
我認為您應該改用-d
標志並將 branchId 作為 object 傳遞。 嘗試
curl -X POST \
http://localhost:8080/sp/salesOrders/uploadSalesOrder \
-H 'Accept: */*' \
-H 'Accept-Encoding: gzip, deflate' \
-H 'Authorization: Basic Mzo5MTQ4MDk0ZjIxMDJhM2Q3M2U0OWY5NDljMGQ2YTIzYw==' \
-H 'Cache-Control: no-cache' \
-H 'Connection: keep-alive' \
-H 'Content-Length: 164' \
-H 'Content-Type: application/x-www-form-urlencoded' \
-H 'Host: localhost:8080' \
-H 'Postman-Token: 6bd29ccf-ebad-4299-8687-9ea46cf35686,4ea8d417-df27-49a1-8d84-3aabddbccd2c' \
-H 'User-Agent: PostmanRuntime/7.19.0' \
-H 'cache-control: no-cache' \
-H 'content-type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW' \
-d '{"branchId": 5}'
我沒有使用multer
。 這就是為什么我在請求正文中得到空白 object 的原因。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.