diff --git a/java/src/org/openqa/selenium/remote/http/jdk/JdkHttpMessages.java b/java/src/org/openqa/selenium/remote/http/jdk/JdkHttpMessages.java index 8aae9ab2bc52ba..5aca1b2401de59 100644 --- a/java/src/org/openqa/selenium/remote/http/jdk/JdkHttpMessages.java +++ b/java/src/org/openqa/selenium/remote/http/jdk/JdkHttpMessages.java @@ -115,7 +115,12 @@ private BodyPublisher notChunkingBodyPublisher(HttpRequest req) { if (length == null) { // read the data into a byte array to know the length - return BodyPublishers.ofByteArray(Contents.bytes(req.getContent())); + byte[] bytes = Contents.bytes(req.getContent()); + if (bytes.length == 0) { + //Looks like we were given a request with no payload. + return BodyPublishers.noBody(); + } + return BodyPublishers.ofByteArray(bytes); } // we know the length of the request and use it