Skip to content

Commit

Permalink
update new blog
Browse files Browse the repository at this point in the history
  • Loading branch information
actions-user committed Aug 15, 2024
1 parent 56c6d9d commit 4e800f5
Show file tree
Hide file tree
Showing 2 changed files with 123 additions and 96 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -112,3 +112,30 @@ private static JSONObject handleResponse(CloseableHttpResponse response) throws
---

![image](https://github.com/user-attachments/assets/56306e4e-d716-458f-a610-7e3603f5016f)


---

3.Java 11 引入的 HttpClient
![image](https://github.com/user-attachments/assets/74050649-35ae-438a-8a2d-accffce0c075)
```java
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;

public class HttpClientExample {
public static void main(String[] args) throws Exception {
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("https://jsonplaceholder.typicode.com/posts"))
.header("Content-Type", "application/json")
.POST(HttpRequest.BodyPublishers.ofString("{\"title\":\"foo\",\"body\":\"bar\",\"userId\":1}"))
.build();

HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());
}
}

```
Loading

0 comments on commit 4e800f5

Please sign in to comment.