Я пытаюсь опубликовать json в API, который, как ожидается, вернет данные json в формате ['token': '', status: '', error: ''], но данные не возвращаются.
Мой пример кода:
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);
});
}
}
Возвращаемое значение равно
Был случай, когда он возвращал правильный ожидаемый формат данных json, но только когда он отображал возвращенную ошибку.
Он вернул ['token': '', status: '', error: 'Ссылка на объект не установлена на экземпляр объекта в web api'], но это было до того, как я добавил
this.http.setDataSerializer('json');
после добавления этой строки данные не возвращаются.
что может быть возможной причиной?
Спасибо