[英]Override the HTTP response status text
How can I override in Tomcat 7 the text of the HttpStatu
s. 我怎样才能在Tomcat的7覆盖的文本
HttpStatu
秒。
I'm using HttpServletResponse.sendError(401, "Invalid username or Password")
, but when I'm looking at the response status in the client it goves 401 Unauthorized
. 我正在使用
HttpServletResponse.sendError(401, "Invalid username or Password")
,但当我在客户端查看响应状态时,它会发布401 Unauthorized
。
Is there any way to override it? 有没有办法覆盖它?
Tomcat no longer supports USE_CUSTOM_STATUS_MSG_IN_HEADER
property. Tomcat不再支持
USE_CUSTOM_STATUS_MSG_IN_HEADER
属性。
Changelog from 8.5.0 : 从8.5.0更改日志:
RFC 7230 states that clients should ignore reason phrases in HTTP/1.1 response messages.
RFC 7230声明客户端应忽略HTTP / 1.1响应消息中的原因短语。 Since the reason phrase is optional, Tomcat no longer sends it.
由于原因短语是可选的,因此Tomcat不再发送它。 As a result the system property org.apache.coyote.USE_CUSTOM_STATUS_MSG_IN_HEADER is no longer used and has been removed.
因此,系统属性org.apache.coyote.USE_CUSTOM_STATUS_MSG_IN_HEADER不再使用且已被删除。 (markt)
(Markt的)
RFC 7230, Hypertext Transfer Protocol (HTTP/1.1): Message Syntax and Routing , June 2014. Section 3.1.2 : RFC 7230, 超文本传输协议(HTTP / 1.1):消息语法和路由 ,2014年6月。 第3.1.2节 :
The reason-phrase element exists for the sole purpose of providing a textual description associated with the numeric status code, mostly out of deference to earlier Internet application protocols that were more frequently used with interactive text clients.
原因 - 短语元素的唯一目的是提供与数字状态代码相关联的文本描述,主要是出于对交互式文本客户端更频繁使用的早期Internet应用程序协议的尊重。 A client SHOULD ignore the reason-phrase content .
客户端应该忽略原因 - 短语内容 。
否 - 响应代码根据RFC 2616设置。如果要将消息传递给用户(到API客户端),请将其写入正文或响应头中
Edit catalina.properties
and add the property: 编辑
catalina.properties
并添加属性:
org.apache.coyote.USE_CUSTOM_STATUS_MSG_IN_HEADER=true
With that set in my dev environment, then when I do: 在我的开发环境中使用该设置,然后当我这样做时:
response.sendError(HttpServletResponse.SC_BAD_REQUEST,
"A very very very bad request");
I see: 我懂了:
HTTP/1.1 400 A very very very bad request
Server: Apache-Coyote/1.1
Content-Type: text/html;charset=utf-8
Content-Language: en
Content-Length: 1024
Date: Fri, 20 Dec 2013 11:09:54 GMT
Connection: close
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.