我是 Java NIO 的新手。我用它来发出 HTTP Get 请求。请求正确执行,但我无法弄清楚如何获取响应的内容。
例如,
CloseableHttpAsyncClient httpClient = HttpAsyncClients.createDefault();
httpClient.start();
url = buildUrl(); //builds the url for the GET request
BasicAsyncResponseConsumer consumer = new BasicAsyncResponseConsumer();
Future<HttpResponse> future = httpClient.execute(HttpAsyncMethods.createGet(url), consumer, null)
现在我如何获取响应的内容?在打印未来时,我得到以下信息:
HTTP/1.1 200 OK [Content-Type: application/json, Date: Fri, 24 Jun 2016 20:21:47 GMT, Content-Length: 903, Connection: keep-alive] [Content-Length: 903,Chunked: false]
我的响应(在浏览器上)是 903 个字符,所以我知道它正确地发出请求。但是,如何打印出结果的 json 内容?