编程语言
首页 > 编程语言> > java – App Engine HTTP状态代码消息

java – App Engine HTTP状态代码消息

作者:互联网

我发现Java的dev_appserver和实时App Engine服务器之间存在不一致.

在我的本地开发服务器上,我有一个返回的Servlet:

return response.sendError(response.SC_BAD_REQUEST, "Please log in to comment");

当我访问页面时,我在标题中返回一个状态代码消息:

Status Code:400 Please log in to comment

将此部署到App Engine时出现问题.当访问同一个servlet时,我收到“Bad Request”而不是“Please login in comment”:

Status Code:400 Bad Request

请登录以注释状态代码消息显示在内容HTML中,但不会出现在标题中,就像在开发环境中一样.

为什么是这样?

编辑

这是dev_appserver和production的curl -vvvv跟踪:

dev_appserver curl trace:

> POST /add-comment HTTP/1.1
> User-Agent: Mozilla/4.0
> Host: localhost:8080
> Accept: */*
> Content-Length: 9
> Content-Type: application/x-www-form-urlencoded
>         
< HTTP/1.1 400 Please log in to comment
< Content-Type: text/html; charset=iso-8859-1
< Cache-Control: must-revalidate,no-cache,no-store
< Content-Length: 1406
< Server: Jetty(6.1.x)

生产卷曲追踪:

> POST /add-comment HTTP/1.1
> User-Agent: Mozilla/4.0
> Host: www.xxx.org
> Accept: */*
> Content-Length: 9
> Content-Type: application/x-www-form-urlencoded
> 
< HTTP/1.1 400 Bad Request
< Content-Type: text/html; charset=utf-8
< Vary: Accept-Encoding
< Date: Thu, 18 Aug 2011 14:04:26 GMT
< Server: Google Frontend
< Cache-Control: private
< Transfer-Encoding: chunked

解决方法:

我会说prod系统是正确的实现. sendError()的javadoc说:

Sends an error response to the client using the specified status. The
server defaults to creating the response to look like an
HTML-formatted server error page containing the specified message
,
setting the content type to “text/html”, leaving cookies and other
headers unmodified. If an error-page declaration has been made for the
web application corresponding to the status code passed in, it will be
served back in preference to the suggested msg parameter.

If the response has already been committed, this method throws an
IllegalStateException. After using this method, the response should be
considered to be committed and should not be written to.

我突出了一个部分.这说它只是在可能的情况下返回带有消息的html页面.它没有说它在HTTP状态代码中使用它(我个人也没有在任何地方看到它:()

标签:java,google-app-engine,http-status-code-400
来源: https://codeday.me/bug/20190521/1147819.html