/** * 与云文件URL建立连接 */ private BufferedInputStream getConnection(String url) { try { URL realUrl = new URL(url); // 打开和URL之间的连接 URLConnection connection = realUrl.openConnection(); // 设置通用的请求属性 connection.setRequestProperty("accept", "*/*"); connection.setRequestProperty("connection", "Keep-Alive"); connection.setRequestProperty("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)"); // 建立实际的连接 connection.connect(); // 定义 BufferedReader输入流来读取URL的响应 return new BufferedInputStream(connection.getInputStream()); } catch (Exception e) { log.error("下载远程文件失败", e); throw new CrmException("下载远程文件失败:" + e.getMessage(), e); } }
java获取url连接
最新推荐文章于 2024-07-13 02:51:28 发布