255. Setting a request body

Setting a request body can be accomplished using HttpRequest.Builder.POST() and HttpRequest.Builder.PUT() or by using method() (for example, method("PATCH", HttpRequest.BodyPublisher)). POST() and PUT() take an argument of the HttpRequest.BodyPublisher type. The API comes with several implementations of this interface (BodyPublisher) in the HttpRequest.BodyPublishers class, as follows:

  • BodyPublishers.ofString()
  • BodyPublishers.ofFile()
  • BodyPublishers.ofByteArray()
  • BodyPublishers.ofInputStream()

We'll take a look at these implementations in the following sections.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.225.235.144