2018-11-02 utils工具类

2018-11-02  本文已影响0人  阿狸爱拢龙

public static String get(String inputStr) throws Exception {
URL url = new URL(inputStr);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");
connection.setConnectTimeout(5000);
InputStream stream = connection.getInputStream();
String intStr = getInputStr(stream);
return intStr;
}

public static String getInputStr(InputStream stream) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(stream));
StringBuffer buffer = new StringBuffer();
String con=null;
while((con=reader.readLine())!=null){
buffer.append(con);
}
return buffer.toString();
}

上一篇 下一篇

猜你喜欢

热点阅读