Ionic 2 not send data.

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';

export class APIProvider {

  constructor() {}

    return new Promise(resolve => {
      let header = {"Content-Type": "application/json"}

      let body = {
        "data_1": "1234567890123",
        "data_2": "125615"
      }'', JSON.stringify(body), header)
      .then(data => {
        console.log(; // data received by server
      .catch(error => {
        console.log(error.error); // error message as string

In api server (PHP), I try var_dump($_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:

  • Cordova CLI: 6.5.0
  • Ionic Framework Version: 2.0.0
  • Ionic CLI Version: 2.2.1
  • Ionic App Lib Version: 2.2.0
  • Ionic App Scripts Version: 1.0.0
  • ios-deploy version: Not installed
  • ios-sim version: Not installed
  • OS: macOS Sierra
  • Node Version: v6.9.5
  • Xcode version: Xcode 8.2.1 Build version 8C1002

Since, status is 200, You have to look into your server code first. Check if you are able to decode your post data properly and if output is coming then what is the format of the output. Is server returning data of “Content-Type”: “application/json”

I think var_dump($_POST); was show every data, They come to server right?
And it not show array(0) { }, Because of didn’t have any data.

Ahhhh, I found the answer.

Just changed "Content-Type": "application/json" to "Content-Type": "application/x-www-form-urlencoded".

I tried this, still getting null values on server side


let body = {
    "data_1": "1234567890123",
    "data_2": "125615"
};'', body, {'Content-Type': 'application/x-www-form-urlencoded'}).then();