Я использую Angular 5 в проекте и делаю вызовы API для извлечения данных.
Пример кода: -
this.userSvc.addPhone(this.userID, this.countryCode, this.phoneNumber)
.subscribe(data => {
console.log('Phone Added Successfully')
},
(err: HttpErrorResponse) => { console.log(err.message) });
userSvc Функция : -
addPhone(userId, countryCode, phoneNumber) {
return this.HttpClient.Post(this.rootUrl + "add-phonetouser?id=" + userId + "&countrycode=" + countryCode + "&phonenumber=" + phoneNumber
, { headers: this.header });
}
Из метода web-api я пытаюсь передатьNoContent HttpCode и хотел бы прочитать код состояния на угловой стороне.
Теперь я хотел бы понять, как мне прочитать этот NoContent HttpStatusCode с угловой стороны.
код веб-API выглядит следующим образом: -
var user = await UserManager.FindByName(username);
if (user == null) {
return Request.CreateResponse(HttpStatusCode.NoContent, "User not found.");
} else {}