@Override public void start() throws Exception { WebClient client = WebClient.create(vertx); MultiMap form = MultiMap.caseInsensitiveMultiMap(); form.add("firstName", "Dale"); form.add("lastName", "Cooper"); form.add("male", "true"); client.post(8080, "localhost", "/").sendForm(form, ar -> { if (ar.succeeded()) { HttpResponse<Buffer> response = ar.result(); System.out.println("Got HTTP response with status " + response.statusCode()); } else { ar.cause().printStackTrace(); } }); } }
@Override public void start() throws Exception { WebClient client = WebClient.create(vertx); MultiMap form = MultiMap.caseInsensitiveMultiMap(); form.add("firstName", "Dale"); form.add("lastName", "Cooper"); form.add("male", "true"); client .post(8080, "localhost", "/") .putHeader("content-type", "multipart/form-data") .sendForm(form, ar -> { if (ar.succeeded()) { HttpResponse<Buffer> response = ar.result(); System.out.println("Got HTTP response with status " + response.statusCode()); } else { ar.cause().printStackTrace(); } }); } }
/** * Like {@link io.vertx.rxjava.ext.web.client.HttpRequest#send} but with an HTTP request <code>body</code> multimap encoded as form and the content type * set to <code>application/x-www-form-urlencoded</code>. * <p> * When the content type header is previously set to <code>multipart/form-data</code> it will be used instead. * @param body the body * @param handler */ public void sendForm(io.vertx.rxjava.core.MultiMap body, Handler<AsyncResult<io.vertx.rxjava.ext.web.client.HttpResponse<T>>> handler) { delegate.sendForm(body.getDelegate(), new Handler<AsyncResult<io.vertx.ext.web.client.HttpResponse<T>>>() { public void handle(AsyncResult<io.vertx.ext.web.client.HttpResponse<T>> ar) { if (ar.succeeded()) { handler.handle(io.vertx.core.Future.succeededFuture(io.vertx.rxjava.ext.web.client.HttpResponse.newInstance(ar.result(), __typeArg_0))); } else { handler.handle(io.vertx.core.Future.failedFuture(ar.cause())); } } }); }
/** * Like {@link io.vertx.rxjava.ext.web.client.HttpRequest#send} but with an HTTP request <code>body</code> multimap encoded as form and the content type * set to <code>application/x-www-form-urlencoded</code>. * <p> * When the content type header is previously set to <code>multipart/form-data</code> it will be used instead. * @param body the body * @param handler */ public void sendForm(io.vertx.rxjava.core.MultiMap body, Handler<AsyncResult<io.vertx.rxjava.ext.web.client.HttpResponse<T>>> handler) { delegate.sendForm(body.getDelegate(), new Handler<AsyncResult<io.vertx.ext.web.client.HttpResponse<T>>>() { public void handle(AsyncResult<io.vertx.ext.web.client.HttpResponse<T>> ar) { if (ar.succeeded()) { handler.handle(io.vertx.core.Future.succeededFuture(io.vertx.rxjava.ext.web.client.HttpResponse.newInstance(ar.result(), __typeArg_0))); } else { handler.handle(io.vertx.core.Future.failedFuture(ar.cause())); } } }); }
@Test public void testFormUrlEncoded() throws Exception { server.requestHandler(req -> { req.setExpectMultipart(true); req.endHandler(v -> { assertEquals("param1_value", req.getFormAttribute("param1")); req.response().end(); }); }); startServer(); MultiMap form = MultiMap.caseInsensitiveMultiMap(); form.add("param1", "param1_value"); HttpRequest<Buffer> builder = client.post("/somepath"); builder.sendForm(form, onSuccess(resp -> complete())); await(); }
@Test public void testFormMultipart() throws Exception { server.requestHandler(req -> { req.setExpectMultipart(true); req.endHandler(v -> { assertEquals("param1_value", req.getFormAttribute("param1")); req.response().end(); }); }); startServer(); MultiMap form = MultiMap.caseInsensitiveMultiMap(); form.add("param1", "param1_value"); HttpRequest<Buffer> builder = client.post("/somepath"); builder.putHeader("content-type", "multipart/form-data"); builder.sendForm(form, onSuccess(resp -> complete())); await(); }
request.queryParams().addAll(queryParams); trackInfo.setRequestTime(Instant.now()); request.sendForm(bodyParams, res -> { trackInfo.setResponseTime(Instant.now()); if (res.succeeded()) {
req.send(handler); req.sendBuffer(Buffer.buffer(), handler); req.sendForm(new CaseInsensitiveHeaders().add("a", "b"), handler); req.sendJson("", handler); req.sendJsonObject(new JsonObject(), handler);