【发布时间】:2016-06-18 05:56:15
【问题描述】:
我的 WebAPI 方法返回错误响应:
return Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "Something bad happened");
在我的客户端(一个 MVC 项目)上,我想显示错误消息,但无法显示“发生了一些事情”的消息:
var response = await client.SendAsync(request);
if (!response.IsSuccessStatusCode)
{
ViewBag.Error= response.ReasonPhrase;
}
除了 ReasonPhrase,我尝试过 response.ToString()、response.Content.ToString() 和 response.Content.ReadAsStringAsync()。他们都没有收到我的消息。 Postman 怎么能显示消息?
知道如何访问消息字符串吗?
【问题讨论】:
-
response.Content.ReadAsStringAsync()应该这样做。您可以发布您尝试这样做的代码吗?可能还有其他错误。 -
我想我知道问题所在,作为答案添加。
标签: c# .net asp.net-mvc asp.net-mvc-4 asp.net-web-api