forked from wesleyegberto/java-new-features
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPostRequestTest.java
More file actions
21 lines (18 loc) · 716 Bytes
/
PostRequestTest.java
File metadata and controls
21 lines (18 loc) · 716 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import java.io.IOException;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import static java.net.http.HttpRequest.*;
public class PostRequestTest {
public static void main(String[] args) throws IOException, InterruptedException {
BodyPublisher body = BodyPublishers.ofString("{'id':1}");
HttpRequest request = newBuilder()
.POST(body)
.uri(URI.create("http://httpbin.org/post"))
.build();
HttpClient httpClient = HttpClientBuilderTest.createHttpClient();
HttpResponse<String> httpResponse = httpClient.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println("Response: " + httpResponse.body());
}
}