Java: JDK HttpClient发送PUT请求

java标志
image-3486

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
var putJson="data";
HttpRequest request =
                    HttpRequest.newBuilder()
                        .uri(
                            URI.create(
                                "http://127.0.0.1/order/save"))
                        .header(
                            "Authorization",
                            "Bearer 12356556898921")
                        .header("Content-Type", "application/json;charset=UTF-8")
                        .method("PUT", HttpRequest.BodyPublishers.ofString(putJson))
                        .build();
                httpclient
                    .sendAsync(request, HttpResponse.BodyHandlers.ofString())
                    .thenApply(HttpResponse::body)
                    .thenAccept(System.out::println)
                    .join();

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注

*

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据