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';
@Component({
selector: 'app-home',
templateUrl: 'home.page.html',
styleUrls: ['home.page.scss'],
})
export class HomePage {
public amessage = '';
public bmessage = '';
public errmessage: boolean = false;
constructor(private http: HTTP) {}
getVehicles() {
this.http.setDataSerializer('json');
this.http.post(
"http://api.*********.com/WebProcessorApi.ashx", //URL
{
"Token":"",
"OperationType":"SignIn",
"InformationType":"User",
"LanguageType":"",
"Arguments": {"UserName":"username","Password":"password"}
}, //Data,
{ "Content-Type": "application/json", "Access-Control-Allow-Origin" : "*"} //Headers
)
.then(response => {
// prints 200
console.log(response.status);
try {
this.amessage = JSON.stringify(response);
// prints test
console.log(response);
//this.amessage = response;
} catch(e) {
console.error('JSON parsing error');
}
})
.catch(response => {
this.errmessage = true;
// prints 403
console.log(response.status);
this.bmessage = response.error;
// prints Permission denied
console.log(response.error);
});
}
}
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
this.http.setDataSerializer('json');
after i added that line, no data is returned.
what could be the possible cause?
Thanks