cz.jalasoft.net.http.HttpPostRequest Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of HttpClient Show documentation
Show all versions of HttpClient Show documentation
API for communicating over HTTP.
The newest version!
/*
* Copyright (c) 2015 Avast a.s., www.avast.com
*/
package cz.jalasoft.net.http;
/**
* A request that is sent over HTTP as a POST request.
*
* @author Jan Lastovicka ([email protected])
* @since 2015-02-21
*/
public abstract class HttpPostRequest extends HttpRequest {
private String payload;
public HttpPostRequest withJsonPayload(String payload) {
this.payload = payload;
this.header(HttpHeader.CONTENT_TYPE, "application/json; charset=utf-8");
return this;
}
public HttpPostRequest withFormParametersPayload(String params) {
this.payload = params;
this.header(HttpHeader.CONTENT_TYPE, "application/x-www-form-urlencoded");
return this;
}
/**
* Gets a payload of a request.
* @return never null or empty.
*/
protected final byte[] payload() {
return payload.getBytes();
}
/**
* Gets a string representation of a payload.
* @return never null or emty.
*/
protected final String payloadAsString() {
return payload;
}
@Override
final HttpPostRequest getThis() {
return this;
}
@Override
public String toString() {
return new StringBuilder("HttpPostRequest[")
.append("URI: ")
.append(uri())
.append(", ")
.append("payload: ")
.append(payload)
.append("]")
.toString();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy