POST method in iOS is not Working

I have a app which in running well in Android. But when I try to run the app in iOS, all the GET method is working properly but the POST method stuck in a preflight issue.

I’m using --------- import { Http} from “@angular/http” and my post method looks like
return new Promise((resolve, reject) => {
this.http.post(‘https://myURL.com/api/postMethod’, “{data: data}”)
.subscribe(data => {
resolve(data.json());
}, (err) => {
reject(err);
});
});

I have also tried with import { HTTP } from ‘@ionic-native/http’; but failed. I have also added the param name=“ios-package” value=“CDVWKWebViewEngine”/> in Config.xml but nothing works for me.

Could anyone please help me on this??

hey , are you sure app works in android because platform does not matter for get or post method.
if you are running on app in browser it will not work because of CORS(control access origin) . for that you have to add CORS extension in particular browser.

for the post method you have to pass headers for authentication such as token no .

here is my code

const httpOptions = {
headers: new HttpHeaders({
‘Content-Type’: ‘application/json’,
‘Authorization’: ‘token’
})
};

  this.http.post( url, data, httpOptions)
    .subscribe(data => {

      this.data = data;

      resolve(this.data);
    },
    error => {
      // probably a bad url or 404
      reject(error);
      this.handleError(error)
    })

}); // end Promise

Continuing the discussion from POST method in iOS is not Working:

Thanks for the suggestion.
Yes my app is running perfectly in Android and its already published at Google Play Store. I’m checking the same app is iOS (12.1.2) but the POST method is not working. :frowning:

have you checked any other ios version ?

No. I’m checking with my iPhone only.

okay first you should check.
and according to me , platform is not require for GET , POST method but for post authentication is necessary so you have to pass header.

Thanks for the Help. Few changes in server side made my day :slight_smile: