I am looking for a solution to POST form data with HttpAsyncClient. All examples I've found so far only sent simple GET requests. This is what I've got so far:
try (CloseableHttpAsyncClient client = HttpAsyncClients.createDefault()) {
SimpleHttpRequest httpPost = SimpleHttpRequests.post("http://httpbin.org");
// How to add key=value as form data to httpPost?
Future<SimpleHttpResponse> future = client.execute(httpPost, new FutureCallback<SimpleHttpResponse>() {
@Override
public void completed(SimpleHttpResponse simpleHttpResponse) {
System.out.println(simpleHttpResponse.getCode());
System.out.println(simpleHttpResponse.getBody());
}
@Override
public void failed(Exception e) {
System.out.println(e);
}
@Override
public void cancelled() {
System.out.println("cancelled");
}
}
}
I also looked around the source code, where I found the SimpleHttpRequest::setBody method and the corresponding SimpleBody class. But they seem, too, not support form data.
Basically, I need the equivalent of OkHttp's FormBody.