I need to send a request to a bank payment API from an Ionic app, using the Angular HTTP Client service. The request shouldn’t triggera CORS preflight because:
- Use a POST verb
- The only header added is Content-Type: text/plain
- The expected response is text/plain.
If I try the request using Postman or Isomnia, I see there is no OPTIONS preflight and the request returns the expected response.
But when I try the same request from Ionic, using this code:
const headers = new HttpHeaders({
"Content-Type": "text/plain",
"Accept": "text/plain"
});
const url = "https://..../Authorize3DS";
this.http
.post(url, xmlData, {
headers: headers
})
then I get this error, both from local server or from the actual app:
{"headers":{"normalizedNames":{},"lazyUpdate":null,"headers":{}},"status":0,"statusText":"Unknown Error","url":"https://.../Authorize3DS","ok":false,"name":"HttpErrorResponse","message":"Http failure response for https://.../Authorize3DS: 0 Unknown Error","error":{"isTrusted":true}}
I am positive that this is a CORS issue because if I install a CORS-enabler on my browser and retry the request, then it works perfectly. Also, I tried other REST servers under HTTPS and they all work perfectly, so it must be something related to the CORS implementations on the bank’s webervice, but I can’t figure out what could it be and what to do in my ionic app to get this working.
Any ideas?
TIA