java - 如何在解析为 dto 之前获取 http Jersey 响应状态?

标签 java rest http jersey jersey-client

我的代码曾经是:

ClientResponse clientResponse = webResource.path("routingRequest")
                    .queryParam("at", rr.at)
                    .get(ClientResponse.class);

我补充说:

RoutingResponse routingResponse = webResource.path("routingRequest")
                    .queryParam("at", rr.at)
                    .get(ClientResponse.class)
                    .getEntity(RoutingResponse.class);

现在我什至没有得到 ClientResponse.class

我怎样才能得到 http 结果代码

您将如何获得此状态?

最佳答案

没有理由不能同时读取客户端响应和实体主体。

    ClientConfig cc = new DefaultClientConfig();
    cc.getProperties().put(
            ClientConfig.PROPERTY_FOLLOW_REDIRECTS, true);
    Client c = Client.create(cc);
    WebResource r = c.resource("https://my_url");
    ClientResponse response = r.get(ClientResponse.class);
    EntityTag e = response.getEntityTag();
    String entity = response.getEntity(String.class);
    System.out.println("The response status is " + response.getStatus());
    System.out.println("The enttiy body is " + entity);

关于java - 如何在解析为 dto 之前获取 http Jersey 响应状态?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28526296/

相关文章:

java - 使用 CommonsMultipartFile 将文件转换为 MultipartFile

json - 我如何解码这个响应体?

http - 接收大文件的Web API的哪种http请求方法

c# - 从 http 服务流式传输大文件

java - 随机访问文件.write : EBADF (Bad file descriptor)

java - Spring kafka @KafkaListener 没有被调用

java - Android SQLite - 删除并重新创建具有相同表名的表时出现错误列

java - Jira Rest API 调用适用于本地程序,但不适用于插件

rest - Protobuf Field Mask 可以应用于 grpc only case 吗?

rest - CFHTTP HTTPS 连接失败 CF8