import java.io.InputStream; import java.net.URL; import java.net.URLConnection; import java.util.Scanner; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** * 远程请求工具类, 10秒的链接超时时间,2秒的读取超时时间 * * */ public class RMIUtil { private static Logger logger = LoggerFactory.getLogger(RMIUtil.class); public static String readALl(String url) { try { URL url_req = new URL(url); logger.info("发起请求:" + url_req); URLConnection con = url_req.openConnection(); con.setReadTimeout(2000); con.setConnectTimeout(10000); InputStream is = con.getInputStream(); StringBuilder sb = new StringBuilder(); Scanner input = new Scanner(is, "utf-8"); String line = ""; while (input.hasNextLine()) { line = input.nextLine(); sb.append(line); } input.close(); String rs = sb.toString(); return rs; } catch (Exception e) { logger.error("请求失败!失败原因:" + e.getMessage()); } return "{}"; }