Quantcast
Channel: Ionic Framework - Ionic Forum
Viewing all articles
Browse latest Browse all 48979

HTTP POST request Ionic 3 gives 403 forbidden

$
0
0

I’m currently working on an app based on ionic 3.9.2. I’m trying to send a POST request to an API but I’m getting a 403 forbidden. orignally I had a CORS issue but I temporarily added https://cors-anywhere.herokuapp.com/ to the URL to bypass that. here is the function:

voucher-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");
    }
  );

and the function it’s refrencing voucherService.editVoucher(voucher) is here:

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);
    
}

1 post - 1 participant

Read full topic


Viewing all articles
Browse latest Browse all 48979

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>