标签:out pci adl trace cti get art 字符串 line
package cn.smartercampus.core.util; import java.io.BufferedReader; import java.io.InputStream; import java.io.InputStreamReader; import java.net.HttpURLConnection; import java.net.URL; public class HttpCilent { public String httpRequest(String req_url) { StringBuffer buffer = new StringBuffer(); try { URL url = new URL(req_url); HttpURLConnection httpUrlConn = (HttpURLConnection) url.openConnection(); httpUrlConn.setDoOutput(false); httpUrlConn.setDoInput(true); httpUrlConn.setUseCaches(false); httpUrlConn.setRequestMethod("GET"); httpUrlConn.connect(); // 将返回的输入流转换成字符串 InputStream inputStream = httpUrlConn.getInputStream(); InputStreamReader inputStreamReader = new InputStreamReader(inputStream, "utf-8"); BufferedReader bufferedReader = new BufferedReader(inputStreamReader); String str = null; while ((str = bufferedReader.readLine()) != null) { buffer.append(str); } bufferedReader.close(); inputStreamReader.close(); // 释放资源 inputStream.close(); inputStream = null; httpUrlConn.disconnect(); } catch (Exception e) { System.out.println(e.getStackTrace()); } return buffer.toString(); } }
HttpURLConnection 当作请求调用接口不带返回参数的工具类
标签:out pci adl trace cti get art 字符串 line
原文地址:https://www.cnblogs.com/remember-forget/p/8953844.html