I has a problem, When I post data to my api server.
My api server didn't get any data, It send from ionic app.
This is my api providers.
import { Injectable } from '@angular/core';
import { HTTP } from 'ionic-native';
import 'rxjs/add/operator/map';
@Injectable()
export class APIProvider {
constructor() {}
getProduct(){
return new Promise(resolve => {
let header = {"Content-Type": "application/json"}
let body = {
"data_1": "1234567890123",
"data_2": "125615"
}
HTTP.post('https://ex.com/api/somethig', JSON.stringify(body), header)
.then(data => {
console.log(data.status);
console.log(data.data); // data received by server
console.log(data.headers);
resolve(data);
})
.catch(error => {
console.log(error.status);
console.log(error.error); // error message as string
console.log(error.headers);
resolve(error);
});
});
}
}
In api server (PHP), I try vardump($_POST);
/ But it return array(0) {}
Console log
[15:20:15] console.log: 200
[15:20:15] console.log: array(0) { }
[15:20:15] console.log: [object Object]
System information:
Ahhhh, I found the answer.
Just changed "Content-Type": "application/json"
to "Content-Type": "application/x-www-form-urlencoded"
.