diff --git a/bundles/org.smarthomej.binding.notificationsforfiretv/src/main/java/org/smarthomej/binding/notificationsforfiretv/internal/NotificationsForFireTVConnection.java b/bundles/org.smarthomej.binding.notificationsforfiretv/src/main/java/org/smarthomej/binding/notificationsforfiretv/internal/NotificationsForFireTVConnection.java index 2bede8f999..970b8f5f6d 100644 --- a/bundles/org.smarthomej.binding.notificationsforfiretv/src/main/java/org/smarthomej/binding/notificationsforfiretv/internal/NotificationsForFireTVConnection.java +++ b/bundles/org.smarthomej.binding.notificationsforfiretv/src/main/java/org/smarthomej/binding/notificationsforfiretv/internal/NotificationsForFireTVConnection.java @@ -19,6 +19,7 @@ import java.net.URI; import java.net.http.HttpClient; import java.net.http.HttpRequest; +import java.net.http.HttpRequest.BodyPublisher; import java.net.http.HttpRequest.BodyPublishers; import java.net.http.HttpResponse; import java.net.http.HttpResponse.BodyHandlers; @@ -103,9 +104,15 @@ public void addFilePart(String name, File file) throws IOException { public String send() throws IOException, InterruptedException { byteArrays.add(("--" + boundary + "--").getBytes(StandardCharsets.UTF_8)); + int length = 0; + for (byte[] bytes : byteArrays) { + length += bytes.length; + } + + BodyPublisher bodyPublisher = BodyPublishers.fromPublisher(BodyPublishers.ofByteArrays(byteArrays), length); HttpRequest httpRequest = HttpRequest.newBuilder() - .header("Content-Type", "multipart/form-data;boundary=" + boundary) - .POST(BodyPublishers.ofByteArrays(byteArrays)).uri(uri).build(); + .header("Content-Type", "multipart/form-data;boundary=" + boundary).POST(bodyPublisher).uri(uri) + .build(); HttpResponse response = httpClient.send(httpRequest, BodyHandlers.ofString()); if (response.statusCode() == HttpURLConnection.HTTP_OK) { return response.body();