- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我正在尝试引发 HttpResponseException
,如该截屏视频中所述(大约 1 分钟)
throw new HttpResponseException(HttpStatusCode.Unauthorized);
但应用程序无法编译,因为它会抛出以下错误:
The best overloaded method match for 'System.Web.Http.HttpResponseException.HttpResponseException(System.Net.Http.HttpResponseMessage)' has some invalid arguments
msdn 上的文档说它有一个接受 HttpResponseMessage
枚举的构造函数。 http://msdn.microsoft.com/en-us/library/hh835324%28v=vs.108%29.aspx
我错过了什么?
谢谢
最佳答案
如果您使用的是 RC,这已经改变了。尝试:
throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.Unauthorized));
关于c# - HttpResponseException 不接受 HttpStatusCode,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10905163/
我试图抛出一个 HttpResponseException(HttpStatusCode.NotFound) 并且我收到以下错误 The response message returned by th
我正在编写一个单元测试方法来执行代码,在我的测试条件下,预计会抛出带有特定响应消息的 HttpResponseException。 我的测试方法代码的相关部分如下所示: try { MyCla
我正在学习 Badrinarayanan Lakshmiraghavan 在“实用 ASP.NET Web API”中的教程。 我认为这表明可以使用一些异常将“404 - Not Found”类型的东
我正在使用 Apache HttpComponents 客户端 POST 到返回 JSON 的服务器。问题是,如果服务器返回 400 错误,我似乎无法判断错误来自 Java(到目前为止不得不求助于数据
我正在尝试通过以下方式返回状态码 throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.Unauthorized
我正在尝试引发 HttpResponseException,如该截屏视频中所述(大约 1 分钟) throw new HttpResponseException(HttpStatusCode.Unau
我在处理 MVC 4 webAPI 中的错误时遇到了一个大问题。在这里,我想验证传入的请求并发回 BadRequest 响应。 为此,我正在使用代码 public Product GetProduct
我已经为我的 Web API Controller 操作创建了一个异常过滤器,但它似乎没有做任何事情(即使它确实被调用)。 属性 public class ExceptionHandlerAttrib
如果出现错误,我会从我调用的 REST 服务中获得 HTTPResponseException。我想从中获取错误消息的详细信息,以便我可以进行相应处理。如何提取返回的HTTPResponseExcep
我试图理解两者并编写示例代码: public HttpResponseMessage Get() { var response = ControllerContext.Request
我正在使用 Apache HttpComponents (4.5.11) 来测试 Web API。 对于负面测试(例如发送错误的请求),我还想检查响应正文,但 CloseableHttpClient
我有一个类: public class ApiExceptionFilterAttribute : ExceptionFilterAttribute,IExceptionFilter {
如何在 ApiController 中向前端返回带有“无效用户名”等文本的错误请求异常。我的代码: public class FrontEndController : ApiController
我的问题的来源是以下代码,它是 Microsoft documentation 中包含的代码片段的一部分对于 asp.net web api 中的异常处理: var resp = new HttpRe
我在 ApiController 的请求处理方法中有这段代码: if (uri != null) { HttpResponseMessage r = Request.CreateRespons
评论一篇文章后Exception Handling in ASP.NET Web API对于何时抛出异常与返回错误响应,我有点困惑。我还想知道当您的方法返回域特定模型而不是 HttpResponseM
来自http://www.asp.net/web-api/overview/web-api-routing-and-actions/exception-handling HttpResponseExc
首先,我遇到了这个问题,在InsertAsync期间,RequestStatus的值无法从客户端传递到Mobile Service,该值将在null中处理(客户端 - 移动应用程序) (服务器 - A
在我的应用程序中,我使用 http 将用户信息发送到服务器,如下所示,我得到 org.apache.http.client.HttpResponseException: Not Found 我花了更多
我正在 ASP 5 中编写一个 api Controller 。如果传递给服务的参数不正确,我想返回一个错误的请求代码异常。在当前版本的 webapi 中,我会这样做: throw new HttpR
我是一名优秀的程序员,十分优秀!