package com.monitor.util;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
public class HttpUrlConnectionUtil {
public static String getMessage(String path) throws Exception
{
URL url = null;
String result = "";
url = new URL(path);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setConnectTimeout(AppConfig.HTTP_CONN_TIMEOUT);
InputStream is = connection.getInputStream();
BufferedReader br = new BufferedReader(new InputStreamReader(is,"utf-8"));
StringBuffer sb = new StringBuffer();
String line = null;
while ((line = br.readLine()) != null) {
sb.append(line + "\n");
}
br.close();
is.close();
connection.disconnect();
result = sb.toString();
//System.out.println(result);
return result;
}
}
HttpURLConnection工具类
最新推荐文章于 2021-12-07 13:11:41 发布