HTTP POST 请求 Ionic 3 给出 403 forbidden
HTTP POST request Ionic 3 gives 403 forbidden
我目前正在开发基于 ionic 3.9.2 的应用程序。我正在尝试向 API 发送 POST 请求,但收到 403 禁止请求。最初我有一个 CORS 问题,但我临时将 https://cors-anywhere.herokuapp.com/
添加到 URL 以绕过它。这是函数:
代金券-details.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");
}
);
}
它引用的函数 voucherService.editVoucher(voucher)
在这里:
voucher.ts:
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
有一些限制 as mentioned here:
From February 1st. 2021, cors-anywhere.herokuapp.com will only serve
requests after the visitor has completed a challenge: The user
(developer) must visit a page at cors-anywhere.herokuapp.com to
temporarily unlock the demo for their browser. This allows developers
to try out the functionality, to help with deciding on self-hosting or
looking for alternatives.
尝试在您的浏览器上手动解锁:https://cors-anywhere.herokuapp.com/corsdemo
我目前正在开发基于 ionic 3.9.2 的应用程序。我正在尝试向 API 发送 POST 请求,但收到 403 禁止请求。最初我有一个 CORS 问题,但我临时将 https://cors-anywhere.herokuapp.com/
添加到 URL 以绕过它。这是函数:
代金券-details.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");
}
);
}
它引用的函数 voucherService.editVoucher(voucher)
在这里:
voucher.ts:
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
有一些限制 as mentioned here:
From February 1st. 2021, cors-anywhere.herokuapp.com will only serve requests after the visitor has completed a challenge: The user (developer) must visit a page at cors-anywhere.herokuapp.com to temporarily unlock the demo for their browser. This allows developers to try out the functionality, to help with deciding on self-hosting or looking for alternatives.
尝试在您的浏览器上手动解锁:https://cors-anywhere.herokuapp.com/corsdemo