Java 无法在GET类型的rest assured for rest web服务中获取标头数据

Java 无法在GET类型的rest assured for rest web服务中获取标头数据,java,rest-assured,apache-wink,Java,Rest Assured,Apache Wink,我得到了RESTAPI,它在响应头中发送一些信息。 我正在使用rest-assured框架编写测试用例,我面临的问题是,作为GET API的响应,我并没有得到服务器在rest API响应中设置的头字符串。 我已经在Rest客户端和HTTP资源中检查了相同的API,在那里我可以在API响应中看到服务器设置的头信息 但在rest-assured响应对象中,服务器设置的头信息不可用 Rest API代码: @Path("/download") @GET @Produces("appl

我得到了RESTAPI,它在响应头中发送一些信息。 我正在使用rest-assured框架编写测试用例,我面临的问题是,作为GET API的响应,我并没有得到服务器在rest API响应中设置的头字符串。 我已经在Rest客户端和HTTP资源中检查了相同的API,在那里我可以在API响应中看到服务器设置的头信息

但在rest-assured响应对象中,服务器设置的头信息不可用

Rest API代码:

 @Path("/download")
    @GET
    @Produces("application/zip")
    public Response downloadContractZipFile(@PathParam("contractId") final String contractId) throws CMException{
        ContractActionRequest contractActionRequest = new ContractActionRequest();
        contractActionRequest.setId(contractId);
        DownloadActionResponse  downloadActionResponse  = (DownloadActionResponse) executeAction(Action.DOWNLOAD, contractActionRequest);

        Response res =  Response
                 .ok(downloadActionResponse.getFilestream(), MediaType.APPLICATION_OCTET_STREAM)
                 .header("content-disposition",downloadActionResponse.getContentDisposition())
                 .header("Expires", "0")
                 .header("Content-Length",  String.valueOf(downloadActionResponse.getContentLength()) )
                 .build();  
        return res;
    }   
上面您可以看到,API正在返回标题中的内容长度。但当我使用rest-assured框架调用上述API时,它不会在头中接收“内容长度”。断言正在失败。 放心测试用例代码:

given().get(propertyURI).then().assertThat().header("Content-Length","7562");


java.lang.AssertionError: Expected header "Content-Length" was not "7562", was "null". Headers are:
X-Powered-By=Servlet/3.0
Cache-Control=no-cache, no-store
Cache-directive=no-cache
Pragma=no-cache
Pragma-Directive=no-cache
Expires=Thu, 01 Jan 1970 00:00:00 GMT
Content-Type=text/html;charset=UTF-8
x-authenticated=false
x-location=https://reena:9453/app/login.jsp?targetApp=OM
Content-Language=en-US
Transfer-Encoding=chunked
我建议您尝试而不是放心,因为它对验证响应头有更好的支持

(免责声明:am Karate dev)

我建议您尝试一下,而不是放心,因为它对验证响应头有更好的支持


(免责声明:am Karate dev)

尝试使用RestAssured.config=RestAssured.config().decoderConfig(decoderConfig().useNowrapforInflatedeCode(true));尝试使用RestAssured.config=RestAssured.config().decoderConfig(decoderConfig().UseNowrapForInflatedeCode(true));