我有一个http客户端,它向RESTful web服务发送请求并接收响应。它在Tomcat 8中部署成功,但当我试图在Tomcat版本8.5及以上版本中部署相同的客户端和服务器时,服务器接收响应代码为200,但响应消息为null而不是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 好的
发布于 2016-11-24 09:13:49
根据tomcat中报道的问题,他们已经停止从tomcat 8.5版本发送“原因短语”。
https://stackoverflow.com/questions/40522145
复制相似问题