/** * Sets the request body. * * This method encodes the content to a byte array using the specified * charset, and sets the Content-Length header *if* the setContentLength * argument is true. * * @param content request body * @param charset Charset used for encoding request body. * @param setContentLength If true, Content-Length header is set, otherwise it is not set. * @return {@code this} */ public Builder body(String content, Charset charset, boolean setContentLength) { requireNonNull(charset, "Charset is not provided."); String sanitised = content == null ? "" : content; return body(sanitised.getBytes(charset), setContentLength); }
/** * Sets the request body. * * This method encodes a String content to a byte array using the specified * charset, and sets the Content-Length header accordingly. * * @param content request body * @param charset Charset for string encoding. * @return {@code this} */ public Builder body(String content, Charset charset) { return body(content, charset, true); }