我可以下载这样的文件:
如果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),它无法下载。我有这个错误
线程“main”中的异常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的连接被拒绝
答案 0 :(得分:0)