Intellij Idea 删除文本java.io.IOException:从消息响应Java Sping Boot

nnsrf1az  于 2023-06-21  发布在  Java
关注(0)|答案(1)|浏览(157)

java.io.IOException
如何在不删除抛出IOException的情况下从respons中删除此异常文本?‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎

private String callUrlApi(int nipp, String nama) throws IOException {
        String apiUrl = "http://---------------------------";
        String encodedNama = URLEncoder.encode(nama, String.valueOf(StandardCharsets.UTF_8));
        String urlString = apiUrl + "?nipp=" + nipp + "&nama=" + encodedNama;

        HttpURLConnection connection = null;
        BufferedReader reader = null;
        StringBuilder response = new StringBuilder();

        try {
            URL url = new URL(urlString);
            connection = (HttpURLConnection) url.openConnection();
            connection.setRequestMethod("GET");
            connection.setRequestProperty("Authorization", "Bearer QGAv_R-w_1621330285");

            reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
            String line;
            while ((line = reader.readLine()) != null) {
                response.append(line);
            }
        } finally {
            if (reader != null) {
                reader.close();
            }
            if (connection != null) {
                connection.disconnect();
            }
        }

        return response.toString();
    }
2ekbmq32

2ekbmq321#

private String callUrlApi(int nipp, String nama) throws IOException {
        String apiUrl = "http://---------------------------";
        String encodedNama = URLEncoder.encode(nama, String.valueOf(StandardCharsets.UTF_8));
        String urlString = apiUrl + "?nipp=" + nipp + "&nama=" + encodedNama;

        HttpURLConnection connection = null;
        BufferedReader reader = null;
        StringBuilder response = new StringBuilder();

        try {
            URL url = new URL(urlString);
            connection = (HttpURLConnection) url.openConnection();
            connection.setRequestMethod("GET");
            connection.setRequestProperty("Authorization", "Bearer QGAv_R-w_1621330285");

            reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
            String line;
            while ((line = reader.readLine()) != null) {
                response.append(line);
            }
        } finally {
            if (reader != null) {
                reader.close();
            }
            if (connection != null) {
                connection.disconnect();
            }
        }

        return response.toString();
    }

相关问题