简体   繁体   English

如何在.NET Core WEB API中返回Continue Http状态代码?

[英]How to return Continue Http status code in .NET Core WEB API?

I'm having troubles setting 100 status code on response. 我在响应时设置100状态代码时遇到了麻烦。 I have tried the following way: 我尝试了以下方法:

HttpContext.Response.StatusCode = 100;

but it does not work, server refused to answer. 但它不起作用,服务器拒绝回答。 Does anybody faced similar issue? 有人遇到过类似的问题吗?

Try using one of the Web API related action results in Controller to get the desired response. 尝试在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
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM