On Fri, 8 Sep 2023 11:32:26 GMT, Daniel Fuchs <[email protected]> wrote:
> If another code than 100 is returned there's no point in sending the request > body, hence the exception. You can get the 200 and the response at this point > by looking at the status code and reading the response input stream. IMHO > it's better than returning null or some other special output stream that > would discard the data (or throw when it's used). It's typically what you'd > expect if 417 was returned, but 200 falls down in the same category too. So > catch the exception and check the status. As per specification (https://www.rfc-editor.org/rfc/rfc9110#section-10.1.1-11.4) if server returns non 100 code then one of the client side requirement is as follows. A client that receives a 417 (Expectation Failed) status code in response to a request containing a 100-continue expectation SHOULD repeat that request without a 100-continue expectation, since the 417 response merely indicates that the response chain does not support expectations (e.g., it passes through an HTTP/1.0 server). I checked with JDK new HttpClient and it don’t throw exception. Please find the below code that works well with my test server. ################################### String requestBody = "This is payload that i am sending it to test."; HttpClient client = HttpClient.newHttpClient(); HttpRequest request = HttpRequest.newBuilder() .uri(URI.create("http://localhost:9000")) .POST(HttpRequest.BodyPublishers.ofString(requestBody)) .expectContinue(true) .build(); HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString()); System.out.println(response.statusCode() + ", " + response.body()); HttpHeaders headers = response.headers(); System.out.println(headers.firstValue("field1")); #################################### ------------- PR Comment: https://git.openjdk.org/jdk/pull/15483#issuecomment-1715501101
