package com.fgkj.test;
|
|
import java.io.BufferedReader;
|
import java.io.IOException;
|
import java.io.InputStream;
|
import java.io.InputStreamReader;
|
import java.net.HttpURLConnection;
|
import java.net.URL;
|
import net.sf.json.JSONObject;
|
|
public class URLConnectionTest {
|
public static void main(String[] args) {
|
try {
|
|
long begintime = System.currentTimeMillis();
|
|
URL url = new URL(
|
"http://192.168.0.34:8919/fuguang/BattInfAction!findMenu");
|
HttpURLConnection urlcon = (HttpURLConnection) url.openConnection();
|
urlcon.connect(); // 获取连接
|
InputStream is = urlcon.getInputStream();
|
BufferedReader buffer = new BufferedReader(
|
new InputStreamReader(is));
|
StringBuffer bs = new StringBuffer();
|
String l = null;
|
while ((l = buffer.readLine()) != null) {
|
//bs.append(l);
|
}
|
String str = bs.toString();
|
JSONObject obj = JSONObject.fromObject(str);
|
System.out.println(obj);
|
//JSONObject.fromObject(str);
|
// System.out.println("1:"+str);
|
//JSONObject json = JSONObject.fromObject(str);
|
// System.out.println("2:"+json);
|
|
|
} catch (IOException e) {
|
System.out.println(e);
|
}
|
}
|
|
}
|