本文整理了Java中reactor.netty.http.client.HttpClient.post()
方法的一些代码示例,展示了HttpClient.post()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HttpClient.post()
方法的具体详情如下:
包路径:reactor.netty.http.client.HttpClient
类名称:HttpClient
方法名:post
[英]HTTP POST to connect the HttpClient.
[中]HTTP POST以连接HttpClient。
代码示例来源:origin: scalecube/scalecube-services
@Override
public Mono<ClientMessage> requestResponse(ClientMessage request) {
return Mono.defer(
() -> {
ByteBuf byteBuf = codec.encode(request);
return httpClient
.post()
.uri(request.qualifier())
.send(
(httpRequest, out) -> {
LOGGER.debug("Sending request {}", request);
// prepare request headers
request.headers().forEach(httpRequest::header);
return out.sendObject(byteBuf).then();
})
.responseSingle(
(httpResponse, bbMono) ->
bbMono.map(ByteBuf::retain).map(content -> toMessage(httpResponse, content)));
});
}
代码示例来源:origin: com.rabbitmq/http-client
private Mono<HttpResponse> doPost(Object body, String... pathSegments) {
return client.headersWhen(authorizedHeader())
.headers(JSON_HEADER)
.chunkedTransfer(false)
.post()
.uri(uri(pathSegments))
.send(bodyPublisher(body))
.response()
.doOnNext(applyResponseCallback())
.map(ReactorNettyClient::toHttpResponse);
}
代码示例来源:origin: reactor/reactor-netty
private Mono<String> login(int port) {
return HttpClient.create()
.port(port)
.wiretap(true)
.post()
.uri("/login")
.responseSingle((res, buf) -> Mono.just(res.status().code() + ""));
}
}
代码示例来源:origin: rabbitmq/hop
private Mono<HttpResponse> doPost(Object body, String... pathSegments) {
return client.headersWhen(authorizedHeader())
.headers(JSON_HEADER)
.chunkedTransfer(false)
.post()
.uri(uri(pathSegments))
.send(bodyPublisher(body))
.response()
.doOnNext(applyResponseCallback())
.map(ReactorNettyClient::toHttpResponse);
}
代码示例来源:origin: reactor/reactor-netty
private void doTestIssue186(HttpClient client) {
Mono<String> content = client.post()
.uri("/")
.send(ByteBufFlux.fromString(Mono.just("bodysample")))
.responseContent()
.aggregate()
.asString();
StepVerifier.create(content)
.expectComplete()
.verify(Duration.ofSeconds(30));
}
代码示例来源:origin: reactor/reactor-netty
HttpClient client = createHttpClientForContextWithPort(server, connectionProvider);
String response = client.post()
.uri("/")
.send(ByteBufFlux.fromString(Mono.just("test")
response = client.post()
.uri("/")
.send(ByteBufFlux.fromString(Mono.just("test")))
代码示例来源:origin: reactor/reactor-netty
.post()
.uri("/upload")
.send((r, out) -> out.sendFile(largeFile))
代码示例来源:origin: reactor/reactor-netty
.post()
.uri("/")
.send(ByteBufFlux.fromString(Mono.just("bodysample")))
代码示例来源:origin: reactor/reactor-netty
.port(server.address().getPort())
.headers(h -> h.add("Expect", "100-continue"))
.post()
.uri("/")
.send(ByteBufFlux.fromString(Flux.just("1", "2", "3", "4", "5")))
代码示例来源:origin: reactor/reactor-netty
@Test
public void testIssue525() {
DisposableServer disposableServer =
HttpServer.create()
.port(0)
.tcpConfiguration(tcpServer ->
tcpServer.doOnConnection(c -> c.addHandlerFirst("decompressor", new HttpContentDecompressor())))
.handle((req, res) -> res.send(req.receive()
.retain()))
.wiretap(true)
.bindNow(Duration.ofSeconds(30));
byte[] bytes = "test".getBytes(Charset.defaultCharset());
String response =
HttpClient.create()
.port(disposableServer.port())
.wiretap(true)
.headers(h -> h.add("Content-Encoding", "gzip"))
.post()
.uri("/")
.send(Mono.just(Unpooled.wrappedBuffer(compress(bytes))))
.responseContent()
.aggregate()
.asString()
.block(Duration.ofSeconds(30));
assertThat(response).isEqualTo("test");
disposableServer.disposeNow();
}
代码示例来源:origin: reactor/reactor-netty
@Test
public void releaseInboundChannelOnNonKeepAliveRequest() {
DisposableServer c = HttpServer.create()
.port(0)
.handle((req, resp) -> req.receive().then(resp.status(200).send()))
.wiretap(true)
.bindNow();
Flux<ByteBuf> src = Flux.range(0, 3)
.map(n -> Unpooled.wrappedBuffer(Integer.toString(n)
.getBytes(Charset.defaultCharset())));
Flux.range(0, 100)
.concatMap(n -> HttpClient.create()
.port(c.address().getPort())
.tcpConfiguration(TcpClient::noSSL)
.wiretap(true)
.keepAlive(false)
.post()
.uri("/return")
.send(src)
.responseSingle((res, buf) -> Mono.just(res.status().code())))
.collectList()
.block();
c.disposeNow();
}
代码示例来源:origin: reactor/reactor-netty
@Test
@Ignore
public void wsTest() {
HttpServer server = HttpServer.create();
server.route(r -> r.get("/search/{search}",
(in, out) -> HttpClient.create()
.wiretap(true)
.post()
.uri("ws://localhost:3000")
.send((requestOut, o) -> o.sendString(Mono.just("ping")))
.response((repliesOut, buf) -> out.sendGroups(buf.window(100)))))
.wiretap(true)
.bindNow()
.onDispose()
.block(Duration.ofSeconds(30));
}
代码示例来源:origin: reactor/reactor-netty
Mono<String> content = client.post()
.uri("/")
.send(ByteBufFlux.fromString(Mono.just("bodysample")
代码示例来源:origin: reactor/reactor-netty
@Test
public void httpRespondsEmpty() {
DisposableServer server =
HttpServer.create()
.port(0)
.route(r ->
r.post("/test/{param}", (req, res) -> Mono.empty()))
.wiretap(true)
.bindNow();
HttpClient client =
HttpClient.create()
.port(server.address().getPort())
.wiretap(true);
Mono<ByteBuf> content =
client.headers(h -> h.add("Content-Type", "text/plain"))
.post()
.uri("/test/World")
.send(ByteBufFlux.fromString(Mono.just("Hello")
.log("client-send")))
.responseContent()
.log("client-received")
.next()
.doOnError(t -> System.err.println("Failed requesting server: " + t.getMessage()));
StepVerifier.create(content)
.expectComplete()
.verify(Duration.ofSeconds(5000));
server.disposeNow();
}
代码示例来源:origin: reactor/reactor-netty
@Test
public void testPreferContentLengthWhenPost() {
DisposableServer server =
HttpServer.create()
.port(0)
.wiretap(true)
.handle((req, res) ->
res.header(HttpHeaderNames.CONTENT_LENGTH,
req.requestHeaders()
.get(HttpHeaderNames.CONTENT_LENGTH))
.send(req.receive()
.aggregate()
.retain()))
.bindNow();
StepVerifier.create(
createHttpClientForContextWithAddress(server)
.chunkedTransfer(false)
.headers(h -> h.add(HttpHeaderNames.CONTENT_LENGTH, 5))
.post()
.uri("/")
.send(Mono.just(Unpooled.wrappedBuffer("hello".getBytes(Charset.defaultCharset()))))
.responseContent()
.aggregate()
.asString())
.expectNextMatches("hello"::equals)
.expectComplete()
.verify(Duration.ofSeconds(30));
server.disposeNow();
}
代码示例来源:origin: reactor/reactor-netty
.post()
.send((req, out) ->
out.sendString(Mono.subscriberContext()
代码示例来源:origin: reactor/reactor-netty
Flux.range(0, this.numberOfTests)
.concatMap(i -> client.followRedirect(true)
.post()
.uri("/login")
.responseContent()
代码示例来源:origin: reactor/reactor-netty
private void doTestPublisherSenderOnCompleteFlushInProgress(boolean useScheduler) {
DisposableServer server =
HttpServer.create()
.port(0)
.handle((req, res) ->
req.receive()
.asString()
.doOnNext(System.err::println)
.then(res.status(200).sendHeaders().then()))
.wiretap(true)
.bindNow(Duration.ofSeconds(30));
Flux<String> flux = Flux.range(1, 257).map(count -> count + "");
if (useScheduler) {
flux.publishOn(Schedulers.single());
}
Mono<Integer> code =
HttpClient.create()
.port(server.address().getPort())
.wiretap(true)
.post()
.uri("/")
.send(ByteBufFlux.fromString(flux))
.responseSingle((res, buf) -> Mono.just(res.status().code()))
.log();
StepVerifier.create(code)
.expectNextMatches(c -> c == 200)
.expectComplete()
.verify(Duration.ofSeconds(30));
server.disposeNow();
}
代码示例来源:origin: reactor/reactor-netty
@Test
public void withConnector() {
DisposableServer server = HttpServer.create()
.port(0)
.handle((req, resp) ->
resp.sendString(Mono.just(req.requestHeaders()
.get("test"))))
.bindNow();
Mono<String> content = createHttpClientForContextWithPort(server)
.mapConnect((c, b) -> c.subscriberContext(Context.of("test", "success")))
.post()
.uri("/")
.send((req, out) -> {
req.requestHeaders()
.set("test",
req.currentContext()
.getOrDefault("test", "fail"));
return Mono.empty();
})
.responseContent()
.aggregate()
.asString();
StepVerifier.create(content)
.expectNext("success")
.verifyComplete();
server.disposeNow();
}
代码示例来源:origin: reactor/reactor-netty
.post()
.uri("/test/World")
.send(ByteBufFlux.fromString(Flux.just("Hello")
内容来源于网络,如有侵权,请联系作者删除!