I am new to Ionic. I am facing the problem when calling the API (https), it returns 0. After doing some research, I think it’s related to CORS.
The API requires to send Bearer token authorization in the header, thus, it causes the failure.
The API return success in both android phone and web browser, however, in the iOS device, it return 0, I had tried using ionic v4, ionic-native, HTTP, XMLHttpRequest and so on. All are working well in both android phone and web browser except iOS device. I had whitelisted the IP address, adding these kinds of header
headers.append('Access-Control-Allow-Origin' , '*'); headers.append('Access-Control-Allow-Methods', 'POST, GET, OPTIONS, PUT'); headers.append('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept'); headers.append('withCredentials', 'true'); headers.append('Access-Control-Allow-Credentials', 'true'); headers.append('Accept','application/json'); headers.append('Content-Type', 'application/json');
no luck at all. Spending two days on this, no result I can get. Anyone can provide a suggestion?