From 0675e7abe560e3bff328c47ddc9c8edb82af2d72 Mon Sep 17 00:00:00 2001 From: Pratik Bodawala <11555656+PratikBodawala@users.noreply.github.com> Date: Mon, 26 Aug 2024 16:03:38 +0530 Subject: [PATCH] fixed #104 --- .../java/io/ionic/android_js_engine/NativeWebAPI.kt | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/packages/android-js-engine/AndroidJSEngine/src/main/java/io/ionic/android_js_engine/NativeWebAPI.kt b/packages/android-js-engine/AndroidJSEngine/src/main/java/io/ionic/android_js_engine/NativeWebAPI.kt index 63ae49ba..14c9ed56 100644 --- a/packages/android-js-engine/AndroidJSEngine/src/main/java/io/ionic/android_js_engine/NativeWebAPI.kt +++ b/packages/android-js-engine/AndroidJSEngine/src/main/java/io/ionic/android_js_engine/NativeWebAPI.kt @@ -80,12 +80,18 @@ class NativeWebAPI { connection.setRequestProperty(it.key, it.value) } - if (options.body != null) { + val requestBody = options.body + if (requestBody != null) { connection.doOutput = true - connection.setChunkedStreamingMode(0) + val contentEncoding = options.headers["Transfer-Encoding"] + if (contentEncoding == "chunked") { + connection.setChunkedStreamingMode(0) + } else { + connection.setFixedLengthStreamingMode(requestBody.size) + } val output = BufferedOutputStream(connection.outputStream) - output.write(options.body) + output.write(requestBody) output.flush() } }