java http 1.1_java11新特性HttpClient
1、get請(qǐng)求
ObjectMapper objectMapper = new ObjectMapper();
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder().uri(URI.create(softPhoneAddress + "/api/cfg/selectAgentBySkill?skilldbid=" + queueId))
.GET()
.build();
try {
HttpResponse response =
client.send(request, HttpResponse.BodyHandlers.ofString());
String body = response.body();
List seatAgentsVo = objectMapper.readValue(body, new TypeReference>() {
});
2、post請(qǐng)求
//objectIds轉(zhuǎn)換成json字符串
Objectids object = new Objectids();
object.setObjectids(objectIds);
ObjectMapper mapper = new ObjectMapper();
String result = null;
try {
result = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(object);
} catch (JsonProcessingException e) {
e.printStackTrace();
}
HttpClient builder = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder(URI.create(softPhoneAddress + "/api/v2/stats/agents"))
.header("Content-Type", "application/json")
.POST(HttpRequest.BodyPublishers.ofString(result))
.build();
try {
HttpResponse send = builder.send(request, HttpResponse.BodyHandlers.ofString());
String body = send.body();
SeatStatus value = mapper.readValue(body, SeatStatus.class);
總結(jié)
以上是生活随笔為你收集整理的java http 1.1_java11新特性HttpClient的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 乐分易是什么贷款
- 下一篇: zmbx是哪个保险公司