我在呼叫后端 API 時收到訊息不可用 400 錯誤請求。我通過 POSTMAN 工具測驗了后端 API。我從郵遞員那里得到正確的輸出。后端作業正常。但是當我在角度方面集成 API 時,我收到如下錯誤,

我的 component.ts 檔案中的訂閱代碼如下所示,
this.modifypercentageService.checkUpdateRoomStatusApiMethod(element.nRoomAllocationId)
.subscribe(data=> {console.log(data)});
我的服務層有以下代碼,
checkUpdateRoomStatusApiMethod(nRoomAllocationId:any)
{
return this.http
.put(
this.baseurlService.getUrl()
this.portNumberService.getJointUseModifyPercentagePortNumber()
this.instituteidentifierService.getInstitute()
'/jointuse/modifypercentage/checkUpdateRoomStatus?nRoomAllocationId=' nRoomAllocationId,
{
headers: this.applicationconfigService.getHeader()
}
);
}
輸出當我通過 POSTMAN 進行后端測驗交叉檢查時,

而且我發現我正在從后端 API 獲取輸出,問題是從角度 UI 端呼叫 api。
故障排除已嘗試,
通過 POSTMAN 工具進行跨域交叉檢查并測驗后端。兩種情況都是正確的。僅在角度側積分時出現問題,
任何人都可以建議適當的指南來參考或有關我在 API 集成時在這里犯的任何錯誤的資訊嗎?
uj5u.com熱心網友回復:
Angular HttpClient PUT 有三個引數
放(網址:字串,正文:任何|空,選項)
您正在傳遞標題代替正文。正確的 put 請求將是
checkUpdateRoomStatusApiMethod(nRoomAllocationId: any) {
return this.http
.put(
this.baseurlService.getUrl()
this.portNumberService.getJointUseModifyPercentagePortNumber()
this.instituteidentifierService.getInstitute()
'/jointuse/modifypercentage/checkUpdateRoomStatus', null,
{
params: { nRoomAllocationId },
headers: this.applicationconfigService.getHeader()
}
);
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/436032.html
