繁体   English   中英

如何从ClientBuilder访问获取请求的响应

[英]How to access the response of a get request from ClientBuilder

我正在使用ClientBuilder从API异步执行多个GET请求。

private static Future<Response> getElevation(Coordinate coordinate) {
    double latatude = coordinate.getLatatude();
    double longatude = coordinate.getLongatude();
    String url = "https://api.open-elevation.com/api/v1/lookup?locations=" + latatude + "%2C%20" + longatude;
    System.out.println("URL : " + url);
    return ClientBuilder.newClient().target(url).request().async().get();
}

我调用上述方法,然后等待直到使用命令完成请求为止。

.isDone()

类型为Future <,Response>的对象上。 但是,我不知道如何从中得到实际的响应。 我知道它应该具有这样的形式;

{"results": [{"latitude": 53.95798659954082, "elevation": 0, "longitude": -4.306156617942942}]} 

我使用了.getResult.toString()和.toString()。 但是看不到还有什么。

先感谢您!

您必须在返回的Future<Response>对象上调用get()

get()
Waits if necessary for the computation to complete, and then retrieves its result.

请参阅Future<V>接口的文档。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM