【问题标题】:How to return Continue Http status code in .NET Core WEB API?如何在 .NET Core WEB API 中返回 Continue Http 状态码?
【发布时间】:2018-01-29 11:41:57
【问题描述】:

我在设置100 响应状态码时遇到问题。 我尝试了以下方法:

HttpContext.Response.StatusCode = 100;

但它不起作用,服务器拒绝回答。有没有人遇到过类似的问题?

【问题讨论】:

  • 您能否在minimal reproducible example 中提供更多有关您尝试做什么的背景信息,并阐明您正在使用的平台。您可以在操作中尝试 `return StatusCode(100);` 以返回带有自定义状态代码的响应。

标签: api http asp.net-core-webapi asp.net-core-1.0 http-status-code-100


【解决方案1】:

尝试使用Controller 中与 Web API 相关的操作结果之一来获得所需的响应。

//returns a response with specified status code
public IActionResult StatusCodeActionResult() {
    return StatusCode(100); //<-- StatusCodeResult
}

//returns a response with specified status code along with an object
public IActionResult StatusCodeWithObjectResult() {
    return StatusCode(100, new { Data = "HelloWorld" }); //<-- ObjectResult
}

【讨论】:

    猜你喜欢
    • 2020-01-18
    • 2023-01-12
    • 2013-12-04
    • 2022-02-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-11-10
    • 1970-01-01
    相关资源
    最近更新 更多