我正在尝试将请求从ASP.NET MVC应用程序发送到ASP.NET Web API应用程序(均在本地主机上启动)。无论我要在Web API结果中返回什么StatusCode,在ASP.NET MVC响应中都是:StatusCode 200-OK。
ASP.NET MVC中的代码:
public async Task<ActionResult> PayAsync()
{
var client = new HttpClient();
client.BaseAddress = new Uri("http://{localHostOfWebApiAPP}");
var result = await client.GetAsync("home/pending");
HttpStatusCode status = result.StatusCode;
//I put here breakpoint to see value of status
return RedirectToAction("Index", "Home");
}
ASP.NET Web API(主页控制器)中的代码:
[ActionName("Pending")]
public async Task<HttpResponseMessage> GetPending()
{
var response = new HttpResponseMessage(HttpStatusCode.InternalServerError);
return response;
}
因此,我希望我的响应为StatusCode 500(InternalServerError),但在MVC应用程序中,HttpStatusCode状态的值始终为200。有什么想法吗?
更新:此问题被标记为重复,但我想不出要使用与我重复的帖子来解决的问题。