diff --git a/src/main/java/com/dynatrace/openkit/protocol/HTTPClient.java b/src/main/java/com/dynatrace/openkit/protocol/HTTPClient.java index 007ec6f1..7bb8dc2d 100644 --- a/src/main/java/com/dynatrace/openkit/protocol/HTTPClient.java +++ b/src/main/java/com/dynatrace/openkit/protocol/HTTPClient.java @@ -253,7 +253,7 @@ private StatusResponse handleResponse(RequestType requestType, HttpURLConnection int responseCode = connection.getResponseCode(); String response = responseCode >= 400 - ? readResponse(connection.getErrorStream()) // error stream is closed in readResponse + ? null : readResponse(connection.getInputStream()); // input stream is closed in readResponse if (logger.isDebugEnabled()) { @@ -363,6 +363,10 @@ int getServerID() { } private static String readResponse(InputStream inputStream) throws IOException { + if (inputStream == null) { + return ""; + } + StringBuilder responseBuilder = new StringBuilder(); // reading HTTP response