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();
}
1条答案
按热度按时间2ekbmq321#