diff --git a/components/http/okHttp/src/main/java/com/microsoft/kiota/http/OkHttpRequestAdapter.java b/components/http/okHttp/src/main/java/com/microsoft/kiota/http/OkHttpRequestAdapter.java index e41ff385..8b6a2f28 100644 --- a/components/http/okHttp/src/main/java/com/microsoft/kiota/http/OkHttpRequestAdapter.java +++ b/components/http/okHttp/src/main/java/com/microsoft/kiota/http/OkHttpRequestAdapter.java @@ -901,9 +901,21 @@ public long contentLength() throws IOException { @Override public void writeTo(@Nonnull BufferedSink sink) throws IOException { + long contentLength = contentLength(); + if (contentLength > 0) { + requestInfo.content.mark((int) contentLength); + } sink.writeAll(Okio.source(requestInfo.content)); if (!isOneShot()) { - requestInfo.content.reset(); + try { + requestInfo.content.reset(); + } catch (Exception ex) { + spanForAttributes.recordException(ex); + // we don't want to fail the request if reset() fails + // reset() was a measure to prevent draining the request + // body by an interceptor before + // the final network request + } } } };