javaweb 後臺使用url接口

String GET_URL="https://wx.hguard.cn:8075/queryProfiledataAction.action?phone="+phone+"&beginnum="+beginnum+"&pagesize="+pagesize+"&sign="+newsignString;
             
             try {
                    URL url = new URL(GET_URL);    // 把字符串轉換爲URL請求地址
                    HttpURLConnection connection = (HttpURLConnection) url.openConnection();// 打開鏈接
                    int code = connection.getResponseCode();
                    connection.connect();// 鏈接會話
                    InputStream inputStream = connection.getInputStream();
                    String str=inputStream.toString();
                    // 獲取輸入流
                    BufferedReader br = new BufferedReader(new InputStreamReader(inputStream));
                    String line;
                    StringBuilder sb = new StringBuilder();
                    while ((line = br.readLine()) != null) {// 循環讀取流
                        sb.append(line);
                    }
                    br.close();// 關閉流
                    connection.disconnect();// 斷開鏈接
                  //  Object json = JSON.toJSON(sb.toString());
                  //  Map parseObject = JSON.parseObject(sb.toString(), Map.class);
                } catch (Exception e) {
                    e.printStackTrace();
                }json

相關文章
相關標籤/搜索