public class NetUtils {
public static String getStr() {
String path = "http://www.meirixue.com/api.php?c=list&a=index";
try {
URL url = new URL(path);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");
connection.setConnectTimeout(3000);
int responseCode = connection.getResponseCode();
if (responseCode == 200) {
InputStream inputStream = connection.getInputStream();
int len;
byte[] arr = new byte[1024 * 20];
ByteArrayOutputStream baos = new ByteArrayOutputStream();
while ((len = inputStream.read(arr)) != -1) {
baos.write(arr, 0, len);
}
return baos.toString();
}
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
}
public static String getStr() {
String path = "http://www.meirixue.com/api.php?c=list&a=index";
try {
URL url = new URL(path);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");
connection.setConnectTimeout(3000);
int responseCode = connection.getResponseCode();
if (responseCode == 200) {
InputStream inputStream = connection.getInputStream();
int len;
byte[] arr = new byte[1024 * 20];
ByteArrayOutputStream baos = new ByteArrayOutputStream();
while ((len = inputStream.read(arr)) != -1) {
baos.write(arr, 0, len);
}
return baos.toString();
}
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
}