No error returned but no data returned on successful json post to api

Hi all,

I am attempting a json post to an api expected to return json data in the format [‘token’: ‘’, status: ‘’, error: ‘’] but no data is returned.

My sample code is :

import { Component } from '@angular/core';
import { HTTP } from '@ionic-native/http/ngx';

  selector: 'app-home',
  templateUrl: '',
  styleUrls: [''],
export class HomePage {

    public amessage = '';
    public bmessage = '';

    public errmessage: boolean = false;

  constructor(private http: HTTP) {}

  getVehicles() {

      "http://api.*********.com/WebProcessorApi.ashx",             //URL
        "Arguments": {"UserName":"username","Password":"password"}

      },         //Data,
      { "Content-Type": "application/json", "Access-Control-Allow-Origin" : "*"} //Headers
     .then(response => {
        // prints 200
        try {
          this.amessage = JSON.stringify(response);
          // prints test
          //this.amessage = response;
        } catch(e) {
          console.error('JSON parsing error');
     .catch(response => {
         this.errmessage = true;
       // prints 403
        this.bmessage = response.error;
       // prints Permission denied


The value returned is

There was an instance when it did return the proper expected data json format but only when it was displaying a returned the error.

It returned [‘token’: ‘’, status: ‘’, error: ‘Object reference not set to an instance of an object in web api’] but that was before I added


after i added that line, no data is returned.

what could be the possible cause?


Please see if your problem persists when using the Angular HttpClient and an HTTPS endpoint.

Hi @rapropos, I had tried with HttpClient but I kept getting CORS errors regarding existing headers and it was suggested that I use ionic native HTTP

Well, that doesn’t seem to be working so great for you. My suggestion would be that CORS needs to be fixed on the server, and once that’s done you can go back to using Angular HttpClient, which is much easier to deal with.

Alas, I have no access to the server. I sent a inquiry to the server admin regarding CORS but till i hear back from them it back to trial and error my end :expressionless:

If all else fails, you can contemplate remedying that by inserting a proxy that you do have access to into the equation.