Apache HttpClient组件挂起?

时间:2016-01-12 19:55:20

标签: java apache-httpclient-4.x

我想在JavaFX应用程序中使用Apache HttpClient组件,但它会挂起,并且在尝试执行时根本不做任何事情。

我正在使用IntelliJ,项目库中只有httpclient-4.5.1.jar和httpcore-4.4.3.jar。

非常感谢任何帮助。

我只是简单地实例化使用它的Class:

HttpDownloadUtility httpDownloadUtility = new HttpDownloadUtility();
httpDownloadUtility.httpDownloadFile(param);

这是班级:

import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;

public class HttpDownloadUtility {

    public void httpDownloadFile(Job job) {

        try {
            CloseableHttpClient httpclient = HttpClients.createDefault();
            HttpGet httpget = new HttpGet("https://www.google.com");
            CloseableHttpResponse response = httpclient.execute(httpget);

            response.close();

            System.out.println("Ran");
        } catch (Exception ex) {
        }
    }
}

0 个答案:

没有答案