本文整理了Java中com.linecorp.armeria.client.HttpClient.post()
方法的一些代码示例,展示了HttpClient.post()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HttpClient.post()
方法的具体详情如下:
包路径:com.linecorp.armeria.client.HttpClient
类名称:HttpClient
方法名:post
[英]Sends an HTTP POST request with the specified content.
[中]发送具有指定内容的HTTP POST请求。
代码示例来源:origin: line/armeria
@Test
public void shouldReturnBadRequestDueToException() {
final ArmeriaReactiveWebServerFactory factory = factory();
runServer(factory, AlwaysFailureHandler.INSTANCE, server -> {
final HttpClient client = httpClient(server);
final AggregatedHttpMessage res1 = client.post("/hello", "hello").aggregate().join();
assertThat(res1.status()).isEqualTo(com.linecorp.armeria.common.HttpStatus.BAD_REQUEST);
final AggregatedHttpMessage res2 = client.get("/hello").aggregate().join();
assertThat(res2.status()).isEqualTo(com.linecorp.armeria.common.HttpStatus.BAD_REQUEST);
});
}
代码示例来源:origin: line/armeria
private static void makeUnframedRequest(String name) throws Exception {
final HttpClient client = new ClientBuilder(server.uri(SerializationFormat.NONE, "/"))
.factory(clientFactory)
.addHttpHeader(HttpHeaderNames.CONTENT_TYPE, MediaType.PROTOBUF.toString())
.build(HttpClient.class);
final SimpleRequest request =
SimpleRequest.newBuilder()
.setPayload(Payload.newBuilder()
.setBody(ByteString.copyFromUtf8(name)))
.build();
try {
client.post("/armeria.grpc.testing.TestService/UnaryCall2", request.toByteArray());
} catch (Throwable t) {
// Ignore, we will count these up
}
}
}
代码示例来源:origin: line/centraldogma
@Test
public void test() {
final HttpClient client = new HttpClientBuilder(rule.uri("/"))
.addHttpHeader(HttpHeaderNames.AUTHORIZATION, "bearer " + secret).build();
AggregatedHttpMessage response;
response = client.get("/projects/" + projectName).aggregate().join();
assertThat(response.status())
.isEqualTo(role == ProjectRole.OWNER || role == ProjectRole.MEMBER ? HttpStatus.OK
: expectedFailureStatus);
response = client.post("/projects/" + projectName + "/repos/" + repoName, HttpData.EMPTY_DATA)
.aggregate().join();
assertThat(response.status()).isEqualTo(permission.contains(Permission.WRITE) ? HttpStatus.OK
: expectedFailureStatus);
response = client.get("/projects/" + projectName + "/repos/" + repoName)
.aggregate().join();
assertThat(response.status()).isEqualTo(permission.isEmpty() ? expectedFailureStatus
: HttpStatus.OK);
}
}
内容来源于网络,如有侵权,请联系作者删除!