サンプルコード

        try {
            URL url = new URL("http://xxx/get?param=xxx");

            HttpURLConnection conn = null;

            try {
                conn = (HttpURLConnection) url.openConnection();
                conn.setRequestMethod("GET");

                if (conn.getResponseCode() == HttpURLConnection.HTTP_OK) {
                    try (InputStreamReader is = new InputStreamReader(connection.getInputStream(),
                                                                       StandardCharsets.UTF_8);
                        BufferedReader bdr = new BufferedReader(is)) {
                        String strInfo;
                        while (strInfo= bdr.readLine()) != null) {
                            System.out.println(strInfo);
                        }
                    }
                }
            } finally {
                if (conn != null) {
                    conn.disconnect();
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
        }

 

Software

Posted by arkgame