Java Code Examples for com.ning.http.client.RequestBuilder#setBody()

The following examples show how to use com.ning.http.client.RequestBuilder#setBody() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Zendesk.java    From scava with Eclipse Public License 2.0 5 votes vote down vote up
private Request req(String method, Uri template, String contentType, byte[] body) {
    RequestBuilder builder = new RequestBuilder(method);
    if (realm != null) {
        builder.setRealm(realm);
    } else {
        builder.addHeader("Authorization", "Bearer " + oauthToken);
    }
    builder.setUrl(template.toString());
    builder.addHeader("Content-type", contentType);
    builder.setBody(body);
    return builder.build();
}
 
Example 2
Source File: NingAsyncHttpRequest.java    From junit-servers with MIT License 5 votes vote down vote up
/**
 * Add request body.
 *
 * @param builder The pending HTTP request.
 * @see RequestBuilder#addFormParam(String, String)
 * @see RequestBuilder#setBody(String)
 */
private void handleBody(RequestBuilder builder) throws IOException {
	if (!hasBody()) {
		log.debug("HTTP Request does not have body, skip.");
		return;
	}

	log.debug("Set body to current request builder using: {}", body);
	builder.setBody(body.getBody());

	if (body.getContentType() != null) {
		builder.setHeader("Content-Type", body.getContentType());
	}
}