Http Post on Ionic?

Hi guys,

Got some issue to proceed a POST request on the latest Ionic.
I pull as a model the Conference App that is my base for my new app now.

When I simply try to do a POST regarding Angular doc :

let headers = new Headers({ 'Content-Type': 'application/json' });
let options = new RequestOptions({ headers })

let res = this.http
    .post('http://localhost/auth/login', { identifier, password }, options)
    .subscribe()

console.log(res)

The request is going to the server but in a OPTIONS method (so my server is returning a 304 / 404).
It should go through a POST method with headers application/json, not OPTIONS.
Any idea ?

Thanks

This is only relevant when developing your app and testing in your browser. This will not happen on a device/simulator. So while you can set Access-Control-Allow-Origin: *, it is not something I would recommend you push to production of your backend if the backend is used elsewhere than only in the apps. Either proxy, or only set the ACAO header while developing.

Like I’ve said elsewhere, your goal shouldn’t really be to get around the OPTIONS request, but to handle it properly. imo

Maybe this’ll work for you…
I have actually never used the RequestOptions type.

let headers = new Headers({ 'Content-Type': 'application/json' });
let res = this.http
    .post('http://localhost/auth/login', { identifier, password }, {headers: headers})
    .subscribe()