public class RequestParams extends org.asynchttpclient.RequestBuilderBase<RequestParams>
client.post("http://server/path", params -> {
// Set request parameters:
params.returnAsByteArray();
params.setHeader("name", "value");
// ...
}).then(rsp -> {
// Success; response in the "rsp" object
}).catchError(err -> {
// Request failed; "err" is a Throwable
});
| Modifier and Type | Field and Description |
|---|---|
protected org.asynchttpclient.AsyncHandler<?> |
handler
Output handler / parser.
|
protected boolean |
returnBytes
Do not parse response as JSON, just return the response body in a
byte-array.
|
protected boolean |
returnHttpHeaders
Copy HTTP response headers into the Meta structure of the response Tree.
|
protected boolean |
returnStatusCode
Copy HTTP response status into the Meta structure of the response Tree.
|
address, bodyGenerator, bodyParts, byteBufferData, byteData, channelPoolPartitioning, charset, compositeByteData, cookies, DEFAULT_NAME_RESOLVER, file, followRedirect, formParams, headers, localAddress, method, nameResolver, proxyServer, queryParams, rangeOffset, readTimeout, realm, requestTimeout, signatureCalculator, streamData, stringData, uri, uriEncoder, virtualHost| Modifier | Constructor and Description |
|---|---|
protected |
RequestParams(java.lang.String method,
boolean isDisableUrlEncoding) |
| Modifier and Type | Method and Description |
|---|---|
RequestParams |
returnAsByteArray()
Do not parse response, just return with a byte array.
|
RequestParams |
returnHttpHeaders()
Copy HTTP response headers into the Meta structure of the response Tree.
|
RequestParams |
returnStatusCode()
Copy HTTP response status into the Meta structure of the response Tree.
|
RequestParams |
setBody(services.moleculer.stream.PacketStream stream)
Read request body from the specified PacketStream.
|
RequestParams |
setBody(services.moleculer.stream.PacketStream stream,
long contentLength)
Read request body from the specified PacketStream.
|
RequestParams |
setBody(io.datatree.Tree data)
Set the request body by the specified Tree (~= JSON object).
|
RequestParams |
transferTo(org.asynchttpclient.AsyncHandler<?> target)
Redirect response to the specified AsyncHandler.
|
RequestParams |
transferTo(java.io.OutputStream target)
Redirect response into the specified OutputStream.
|
RequestParams |
transferTo(services.moleculer.stream.PacketStream target)
Redirect response into the specified PacketStream.
|
RequestParams |
transferTo(java.nio.channels.WritableByteChannel target)
Redirect response into the specified WritableByteChannel.
|
addBodyPart, addCookie, addFormParam, addHeader, addHeader, addHeader, addOrReplaceCookie, addQueryParam, addQueryParams, build, clearHeaders, resetCookies, resetFormParams, resetMultipartData, resetNonMultipartData, resetQuery, setAddress, setBody, setBody, setBody, setBody, setBody, setBody, setBody, setBody, setBody, setBodyParts, setChannelPoolPartitioning, setCharset, setCookies, setFollowRedirect, setFormParams, setFormParams, setHeader, setHeader, setHeader, setHeaders, setHeaders, setLocalAddress, setMethod, setNameResolver, setProxyServer, setProxyServer, setQueryParams, setQueryParams, setRangeOffset, setReadTimeout, setRealm, setRealm, setRequestTimeout, setSignatureCalculator, setSingleHeaders, setUri, setUrl, setVirtualHostprotected boolean returnStatusCode
protected boolean returnHttpHeaders
protected org.asynchttpclient.AsyncHandler<?> handler
protected boolean returnBytes
protected RequestParams(java.lang.String method,
boolean isDisableUrlEncoding)
public RequestParams setBody(io.datatree.Tree data)
data - input JSON structurepublic RequestParams setBody(services.moleculer.stream.PacketStream stream)
stream - source PacketStreampublic RequestParams setBody(services.moleculer.stream.PacketStream stream, long contentLength)
stream - source PacketStreamcontentLength - length of the content (in bytes)public RequestParams transferTo(org.asynchttpclient.AsyncHandler<?> target)
target - target AsyncHandlerpublic RequestParams transferTo(services.moleculer.stream.PacketStream target)
target - target PacketStreampublic RequestParams transferTo(java.io.OutputStream target)
target - target OutputStreampublic RequestParams transferTo(java.nio.channels.WritableByteChannel target)
target - target WritableByteChannelpublic RequestParams returnHttpHeaders()
client.post("http://server/path", params -> {
params.returnHttpHeaders();
}).then(rsp -> {
// Get response status
Tree headers = rsp.getMeta().get("$headers");
for (Tree header : headers) {
String name = header.getName();
String value = header.asString();
}
})
public RequestParams returnStatusCode()
client.post("http://server/path", params -> {
params.returnStatusCode();
}).then(rsp -> {
// Get response status
int status = rsp.getMeta().get("$status", 0);
})
public RequestParams returnAsByteArray()
client.post("http://server/path", params -> {
// Do not parse the response as JSON
params.returnAsByteArray();
}).then(rsp -> {
// Success
byte[] bytes = rsp.asBytes();
}).catchError(err -> {
// Failed
err.printStackTrace();
});