原生httpget请求:
public static byte[] getInfo(String url) {
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
InputStream in = null;
try {
String urlNameString = url;
URL realUrl = new URL(urlNameString);
URLConnection connection = realUrl.openConnection();
connection.setRequestProperty("accept", "*/*");
connection.setRequestProperty("connection", "Keep-Alive");
connection.setRequestProperty("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");
connection.connect();
in = connection.getInputStream();
byte[] arr = new byte[2048];
int count = 0;
while ((count = in.read(arr)) != -1) {
byteArrayOutputStream.write(arr, 0, count);
}
in.close();
} catch (Exception e) {
e.printStackTrace();
} finally {
return byteArrayOutputStream.toByteArray();
}
}