java:Tomcat 9状态码200,但响应消息为空



我有一个http客户端,它向RESTful web服务发送请求并接收响应。在Tomcat 8中部署时,它可以成功地工作。但是,当我尝试在Tomcat 8.5及以上版本中部署相同的客户端和服务器时,服务器接收到响应代码为200,但响应消息为空而不是OK。

下面是我的客户端代码片段

        httpclient = HttpClientBuilder.create().build();
        postrequest.setEntity(new UrlEncodedFormEntity(urlParameters));
        HttpResponse response = httpclient.execute(postrequest);
        
        HttpEntity entity = response.getEntity();
        System.out.println("Response from server ");
        System.out.println(response.getStatusLine().getStatusCode());
        System.out.println(response.getStatusLine().getReasonPhrase());

和响应的服务器代码片段是

@POST
@Path("/download/{filename}")
@Produces(MediaType.APPLICATION_OCTET_STREAM)
public Response getFile(@PathParam("filename") String file)
{
    try
    {               
        File downloadfile = new File("/home/upload/"+file);
        ResponseBuilder response = Response.ok((Object) downloadfile);
        response.header("Content-Disposition", downloadfile.getName());
        
        return response.build();
            
    }
    catch(Exception e)
    {
        logger.error("Error is : "+e);
        e.printStackTrace();
    }
    
    
}
我得到的输出就是

服务器的响应

200年

应该是

服务器的响应

200年

好吧

根据tomcat报告的问题,他们已经从tomcat 8.5版本开始停止发送"Reason Phrase"。

https://bz.apache.org/bugzilla/show_bug.cgi?id=60183

最新更新