【发布时间】:2019-07-02 07:06:58
【问题描述】:
我试图通过在 Angular 中通过 POST 请求向 WebApi 传递用户的电子邮件来获取 UserProfile 详细信息,但我无法获取数据。我收到此错误:输入意外结束。
这是调用的方法:
getUserProfile(resourceEmail: string): Observable<any> {
debugger
return this.http.post<UserVM>(this.getAPI('FetchUserProfile')+'/? emailId='+resourceEmail,
this.httpOptions).pipe(
map(data => data),
catchError(this.handleError<any>())
);
}
控制器动作代码
[System.Web.Mvc.HttpPost]
[System.Web.Mvc.Route("ApiWithAction")]
public HttpResponseMessage FetchUserProfile(string emailId)
{
try
{
HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.OK, _userProfileService.GetUserProfile(emailId));
return response;
}
catch (Exception ex)
{
//client.TrackException(ex.InnerException);
return null; //need to check and confirm what needs return to UI
}
}
订阅代码
getBookingList() {
this.bookingListSubscription = this.restService.getCompletedListForGrid(this.booking).subscribe(
data => {
this.bookingList = data;
this.bookingList.forEach((element) => {
element.StartDate = new Date(element.StartDate),
element.EndDate = new Date(element.EndDate);
});
this.gridData = this.bookingList;
this.spinner.hide();
});
【问题讨论】:
-
发布您与订阅相关的代码
-
@Pradeep Jain 我已经用订阅代码更新了问题
-
你试过我的建议了吗?
-
是的,我试过但得到同样的错误
-
你能创建同样的 stackblizt 吗?
标签: angular asp.net-web-api angular6