A-S*_*ani 2 c# asp.net http http-status-codes asp.net-web-api2
题
如何修改状态代码文本(说明/标题)?
例
例如:我想200 (Ok)改为200 (My Custom Text)
应将描述
我想用自定义状态代码(未预留)431创建HTTP响应.我想修改它的文本:
200 (OK)400 (Bad Request)431 (My message here)我试过了:
var response = new HttpResponseMessage()
{
StatusCode = (HttpStatusCode) 431,
};
response.Headers.Add("Status Code", "431 My custom text"); // This throws error.
Run Code Online (Sandbox Code Playgroud)
只需在初始化程序中添加ReasonPhrase:
var response = new HttpResponseMessage()
{
StatusCode = (HttpStatusCode)431,
ReasonPhrase = "your text"
};
Run Code Online (Sandbox Code Playgroud)
它定义了使用状态代码发送的消息文本