HTTP POST请求Ionic 3给出403被禁止



我目前正在开发一款基于ionic 3.9.2的应用程序。我正在尝试向API发送POST请求,但我得到了403禁止。最初我有一个CORS问题,但我暂时将https://cors-anywhere.herokuapp.com/添加到URL中以绕过它。这是功能:

担保人详细信息.ts:

editVoucher(voucher) {
voucher.Comments = (voucher.Comments || " ");
if (!voucher.Comments.includes('Edited via Guide App')) {
voucher.Comments += " Edited via Guide App";
}
//WORKS UP TILL HERE
this.voucherService.editVoucher(voucher)
//      .map((res) => res.json())
.map((res) => res)
.subscribe(
(res) => {
console.log("old voucher id", voucher.voucher_Id);
console.log("new voucher id", res);
this.showSuccess("Voucher updated successfully");
},
(err) => {
console.log("Error occured while updating voucher id "),
this.showError("Oops, an error occured. Please try again");
}
);

}

它重新定义CCD_ 2的函数是:

担保人:

public editVoucher(voucherToUpdate) {
//application/x-www-form-urlencoded
const httpOptions = {
headers: new HttpHeaders({
'Content-Type':  'application/json',
// Authorization: 'my-auth-token'
})
};
return this.HttpClient.post(`https://cors-anywhere.herokuapp.com/${API_BASE_URL}/Api/GuideApp/UpdateVoucher`, {
Voucher: voucherToUpdate,
tenantId: voucherToUpdate.tenantId

}, httpOptions);

}

让我们承认您的代码很好,并根据服务器的需要传递身份验证凭据。cors-anywhere有一些限制,如下所述:

从2月1日开始。2021年,cors-anywhere.herokuapp.com仅提供服务访问者完成挑战后的请求:用户(开发者(必须访问cors-anywhere.herokuapp.com上的页面暂时解锁他们浏览器的演示。这允许开发人员尝试该功能,帮助决定自托管或寻找替代方案。

尝试在浏览器上手动解锁:https://cors-anywhere.herokuapp.com/corsdemo

最新更新