public static String sendGet(String url){
String message = null;
try {
URL urlGet = new URL(url);
HttpURLConnection http = (HttpURLConnection) urlGet.openConnection();
//必须是get方式请求
http.setRequestMethod("GET");
http.setRequestProperty("Content-Type","application/x-www-form-urlencoded");
http.setRequestProperty("Cookie", "dsdsd");
http.setRequestProperty("Referer", url);
http.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; CIBA)");
http.setDoOutput(true);
http.setDoInput(true);
System.setProperty("sun.net.client.defaultConnectTimeout", "30000");//连接超时30秒
System.setProperty("sun.net.client.defaultReadTimeout", "30000"); //读取超时30秒
http.connect();
InputStream is =http.getInputStream();
int size =is.available();
byte[] jsonBytes =new byte[size];
is.read(jsonBytes);
message=new String(jsonBytes,"UTF-8");
System.out.println("getMessage = "+message);
} catch (Exception e) {
e.printStackTrace();
}
return message;
}
添加回答
举报
0/150
提交
取消