Search code examples
javapostmultipartform-datajava-9java-http-client

Java 9 HttpClient still in incubation?


Saw from Javadoc of HttpClient -

Incubating Feature. Will be removed in a future release.

And it doesn't seem to support application/x-www-form-urlencoded or multipart/form-data POST. See this post:

Java 9 HttpClient send a multipart/form-data request


Solution

  • The HTTP/2 Client (JEP 110) is still in incubation for JDK 9. See JDK-8170648:

    Standardizing the API will be deferred to a future release. The API will be included in JDK 9 as an incubating feature ( see incubator modules JDK-8169768).

    In this comment of JDK-8042950 you can find some reasons why it was deferred.

    About the content type support: You can set any MIME type you like, but there does not seem to be any encoders that will produce a particular body format. In other words, it possible to use application/x-www-form-urlencoded and multipart/form-data but you have to encode the body in the correct format yourself, by implementing a BodyProcessor like in the linked answer.

    It could be that they'll more add body processors in the future (though the proposal page says the API is supposed to stay very minimal) but for now I would probably just switch to a more feature-rich client or take adopt the body encoder from an existing library to make it work with the HTTP/2 client.