1
81041
2019-06-24 7a764effdf2e4f0ff2753f81cdb6f83bc8bd9b0b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
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);
        }
    }
 
}