0

我可以下载这样的文件:

如果 url 是,例如 http:/b.net/Doc1.pdf 它下载得很好,但如果是,例如 "https:/mail.google.com/mail/u/0/?ui=2&ik=e3036d4c0a&view =att&th=13c8b8af8687d931&attid=0.1&disp=safe&realattid=f_hckh9zby0&zw"(gmail 附件pdf),无法下载。我有那个错误

线程“主”org.apache.http.conn.HttpHostConnectException 中的异常:与https://mail.google.com的连接被拒绝

HttpClient httpclient = new DefaultHttpClient();
        HttpGet httpget = new HttpGet(url);
        HttpResponse response = httpclient.execute(httpget);

        HttpEntity entity = response.getEntity();
        if (entity != null) {
            long len = entity.getContentLength();
            InputStream inputStream = entity.getContent();
            File temp = File.createTempFile("Google", ".pdf", new File("/")); 
            OutputStream output = new FileOutputStream(temp);
            byte[] buffer = new byte[1024];
            int n = 0;
            while ((n = inputStream.read(buffer)) != -1){
                output.write(buffer, 0, n);
            }
            output.close();
        }

org.apache.http.conn.HttpHostConnectException:连接到https://mail.google.com被拒绝

4

1 回答 1

0

我已经解决了这个问题“ http://hc.apache.org/httpcomponents-client-ga/httpclient/examples/org/apache/http/examples/client/ClientExecuteProxy.java

我有代理问题;

于 2013-02-01T13:20:49.047 回答