Hello
I'm developing an app with Cordova / Ionic and I'm trying to send data via post like this:
public async login(usuario: string, senha: string): Promise<any[]>{
let body = new FormData();
body.append('usuario', usuario);
body.append('senha', senha);
let response: any = await this.http
.post(this.api.url + '?model=usuario&function=login', body, {
headers: {
'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8',
'Token': this.api.token
}
})
.toPromise()
.catch(error => console.log(error));
console.dir(response);
if(response == null){
response = [];
}
return response;
}
I happen to be at localhost and the api at an external php site. I have been able to make requests via get, but the post does not work, api does not receive any data.
To get around cross origin problems I made a proxys definition in the ionic.config.json file.
When I run the function that performs POST, I can see four requests being sent using the chrome debug:
Request URL: link Request Method: GET Status Code: 301 Moved Permanently
Request URL: link Request Method: POST Status Code: 301 Moved Permanently
Request URL: link Request Method: OPTIONS Status Code: 200 OK
Request URL: link Request Method: GET Status Code: 200 OK
...
It seems like where it would be to send a POST ends up sending a GET.