Java HTTP Client输出空JSON

我正在运行以下代码:

CloseableHttpClient httpclient = HttpClients.createDefault();
HttpGet httpGet = new HttpGet("http://10.0.0.22:8086/db/cadvisorDB/series?u=root&p=root&q=select%20max(memory_usage)%20from%20stats%20where%20container_name%20%3D%27execution_container_"+bench_list+"_"+i+"%27%20and%20memory_usage%20%3C%3E%200%20group%20by%20container_name");
//Thread.sleep(10000);
CloseableHttpResponse requestResponse = httpclient.execute(httpGet);
String response=EntityUtils.toString(requestResponse.getEntity());
System.out.println(response);

输出控制台:

[]

当我等待HttpResponse 30s时,它可以工作.我得到了完整的响应(带数据点的JSON):

Thread.sleep(30000);

是否可以使用Apache Java客户端告诉客户端等到获得的值不同于“[]”.我的意思是一个非空的Json.

使用超时并不能解决问题.

先感谢您

最佳答案 然后设置超时将起作用.

HttpGet request = new HttpGet(url);

    // set timeouts as you like
    RequestConfig config = RequestConfig.custom()
            .setSocketTimeout(60 * 1000).setConnectTimeout(20 * 1000)
            .setConnectionRequestTimeout(20 * 1000).build();

    request.setConfig(config);
点赞