本文整理了Java中io.vertx.reactivex.ext.web.client.WebClient.post()
方法的一些代码示例,展示了WebClient.post()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。WebClient.post()
方法的具体详情如下:
包路径:io.vertx.reactivex.ext.web.client.WebClient
类名称:WebClient
方法名:post
暂无
代码示例来源:origin: io.gravitee.elasticsearch/gravitee-common-elasticsearch
/**
* Perform an HTTP search query
* @param indexes indexes names. If null search on all indexes
* @param type document type separated by comma. If null search on all types
* @param query json body query
* @return elasticsearch response
*/
public Single<SearchResponse> search(final String indexes, final String type, final String query) {
// index can be null _search on all index
final StringBuilder url = new StringBuilder()
.append('/')
.append(indexes);
if (type != null) {
url.append('/').append(type);
}
url.append(URL_SEARCH);
return httpClient
.post(url.toString())
.putHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
.rxSendBuffer(Buffer.buffer(query))
.map(response -> {
if (response.statusCode() != HttpStatusCode.OK_200) {
logger.error("Unable to search: url[{}] status[{}] query[{}] response[{}]",
url.toString(), response.statusCode(), query, response.body());
throw new ElasticsearchException("Unable to search");
}
return mapper.readValue(response.bodyAsString(), SearchResponse.class);
});
}
代码示例来源:origin: com.cv4j.netdiscovery/netdiscovery-core
httpRequest = webClient.post(443,request.getUrlParser().getHost(),Preconditions.isNotBlank(request.getUrlParser().getQuery())?request.getUrlParser().getPath()+"?"+request.getUrlParser().getQuery():request.getUrlParser().getPath()).ssl(true);
代码示例来源:origin: io.gravitee.elasticsearch/gravitee-common-elasticsearch
@Override
public Single<BulkResponse> bulk(final List<String> data) {
if (data != null && !data.isEmpty()) {
String content = data.stream().collect(Collectors.joining());
return httpClient
.post(URL_BULK)
.putHeader(HttpHeaders.CONTENT_TYPE, "application/x-ndjson")
.rxSendBuffer(Buffer.buffer(content))
.map(response -> {
if (response.statusCode() != HttpStatusCode.OK_200) {
logger.error("Unable to bulk index data: status[{}] data[{}] response[{}]",
response.statusCode(), content, response.body());
throw new ElasticsearchException("Unable to bulk index data");
}
return mapper.readValue(response.bodyAsString(), BulkResponse.class);
});
}
return Single.never();
}
代码示例来源:origin: cescoffier/vertx-kubernetes-workshop
/**
* Example of method not using a circuit breaker.
*
* @param rc the routing context
*/
private void delegate(RoutingContext rc) {
HttpEndpoint.rxGetWebClient(discovery, svc -> svc.getName().equals("currency-3rdparty-service"))
.flatMap(client -> client.post("/").rxSendJsonObject(rc.getBodyAsJson()))
.map(HttpResponse::bodyAsBuffer)
.subscribe(toObserver(rc));
}
代码示例来源:origin: FroMage/redpipe
.put("client_secret", clientSecret)
.put("code", code);
HttpResponse<JsonObject> response = await(webClient.post(443, "github.com", "/login/oauth/access_token")
.putHeader("Accept", "application/json")
.putHeader("Content-Type", "application/json")
代码示例来源:origin: FroMage/redpipe
.put("client_secret", clientSecret)
.put("code", code);
HttpResponse<JsonObject> response = await(webClient.post(443, "github.com", "/login/oauth/access_token")
.putHeader("Accept", "application/json")
.putHeader("Content-Type", "application/json")
代码示例来源:origin: FroMage/redpipe
.setSsl(true)
.setUserAgent("vert-x3"));
HttpResponse<JsonObject> response = await(webClient.post(443, "api.github.com", "/gists")
.putHeader("Accept", "application/vnd.github.v3+json")
.putHeader("Content-Type", "application/json")
代码示例来源:origin: FroMage/redpipe
.setSsl(true)
.setUserAgent("vert-x3"));
HttpResponse<JsonObject> response = await(webClient.post(443, "api.github.com", "/gists")
.putHeader("Accept", "application/vnd.github.v3+json")
.putHeader("Content-Type", "application/json")
代码示例来源:origin: Cognifide/knotx
private void testPostRequest(VertxTestContext context, Vertx vertx, String url,
Consumer<HttpResponse<Buffer>> expectedResponse) {
WebClient client = WebClient.create(vertx);
MultiMap formData = MultiMap.caseInsensitiveMultiMap();
formData.add("a", "b");
Single<HttpResponse<Buffer>> httpResponseSingle = client
.post(KnotxServerRoutingTest.KNOTX_SERVER_PORT,
KnotxServerRoutingTest.KNOTX_SERVER_ADDRESS,
url)
.rxSendForm(formData);
subscribeToResult_shouldSucceed(context, httpResponseSingle, expectedResponse);
}
代码示例来源:origin: Cognifide/knotx
@Test
@KnotxApplyConfiguration("io/knotx/server/test-server-csrf.json")
public void whenDoPostSecureWithCSRF_expectOK(
VertxTestContext context, Vertx vertx) {
createPassThroughKnot(vertx, "test-splitter");
createPassThroughKnot(vertx, "test-assembler");
createSimpleKnot(vertx, "some-knot", "test", null);
MultiMap body = MultiMap.caseInsensitiveMultiMap().add("field", "value");
WebClient client = WebClient.create(vertx);
client.get(KNOTX_SERVER_PORT, KNOTX_SERVER_ADDRESS, "/content/local/simple.html").send(
ar -> {
if (ar.succeeded()) {
String token = getToken(ar.result().cookies());
client.post(KNOTX_SERVER_PORT, KNOTX_SERVER_ADDRESS, "/content/local/simple.html")
.putHeader(CSRFHandler.DEFAULT_HEADER_NAME, token)
.putHeader(HttpHeaderNames.COOKIE.toString(),
CSRFHandler.DEFAULT_COOKIE_NAME + "=" + token)
.sendForm(body, res -> {
if (res.succeeded()) {
assertEquals(HttpResponseStatus.OK.code(), res.result().statusCode());
context.completeNow();
} else {
context.failNow(ar.cause());
}
});
} else {
context.failNow(ar.cause());
}
});
}
代码示例来源:origin: Cognifide/knotx
@Test
@KnotxApplyConfiguration("io/knotx/server/test-server-csrf.json")
public void whenDoPostSecureWithoutCSRF_expectForbidden(
VertxTestContext context, Vertx vertx) {
createPassThroughKnot(vertx, "test-splitter");
createPassThroughKnot(vertx, "test-assembler");
createSimpleKnot(vertx, "some-knot", "test", null);
MultiMap body = MultiMap.caseInsensitiveMultiMap().add("field", "value");
WebClient client = WebClient.create(vertx);
Single<HttpResponse<Buffer>> httpResponseSingle = client
.post(KNOTX_SERVER_PORT, KNOTX_SERVER_ADDRESS, "/content/local/simple.html")
.rxSendForm(body);
subscribeToResult_shouldSucceed(context, httpResponseSingle, result -> {
assertEquals(HttpResponseStatus.FORBIDDEN.code(), result.statusCode());
});
}
代码示例来源:origin: Cognifide/knotx
@Test
@KnotxApplyConfiguration("io/knotx/server/test-server-csrf.json")
public void whenDoPostPublicWithoutCSRF_expectOk(
VertxTestContext context, Vertx vertx) {
createPassThroughKnot(vertx, "test-splitter");
createPassThroughKnot(vertx, "test-assembler");
createSimpleKnot(vertx, "some-knot", "test", null);
MultiMap body = MultiMap.caseInsensitiveMultiMap().add("field", "value");
WebClient client = WebClient.create(vertx);
Single<HttpResponse<io.vertx.reactivex.core.buffer.Buffer>> httpResponseSingle = client
.post(KNOTX_SERVER_PORT, KNOTX_SERVER_ADDRESS, "/content/local/public.html")
.rxSendForm(body);
subscribeToResult_shouldSucceed(context, httpResponseSingle, resp -> {
assertEquals(HttpResponseStatus.OK.code(), resp.statusCode());
});
}
代码示例来源:origin: io.vertx/vertx-rx-java2
@Test
public void testPost() {
int times = 5;
waitFor(times);
HttpServer server = vertx.createHttpServer(new HttpServerOptions().setPort(8080));
server.requestStream().handler(req -> req.bodyHandler(buff -> {
assertEquals("onetwothree", buff.toString());
req.response().end();
}));
try {
server.listen(ar -> {
client = WebClient.wrap(vertx.createHttpClient(new HttpClientOptions()));
Observable<Buffer> stream = Observable.just(Buffer.buffer("one"), Buffer.buffer("two"), Buffer.buffer("three"));
Single<HttpResponse<Buffer>> single = client
.post(8080, "localhost", "/the_uri")
.rxSendStream(stream);
for (int i = 0; i < times; i++) {
single.subscribe(resp -> complete(), this::fail);
}
});
await();
} finally {
server.close();
}
}
内容来源于网络,如有侵权,请联系作者删除!