日期:2014-05-20 浏览次数:21037 次
public void test() throws Throwable {
String path = "http://10.0.2.2:8080/GETDemo/MyServlet?format=name";
URL url = new URL(path);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setReadTimeout(5 * 1000);
conn.setRequestMethod("GET");
InputStream inputStream=conn.getInputStream();
int total=conn.getInputStream().available();
byte[]b=new byte[total];
inputStream.read(b);
String str=new String(b,"gbk");
System.out.println(str);
}