Skip to content

Commit bdf8817

Browse files
committed
add headers ex
1 parent d4715a7 commit bdf8817

2 files changed

Lines changed: 5 additions & 3 deletions

File tree

core-java-9/run-httpclient.bat

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
java --module-path mods -m com.baeldung.httpclient/com.baeldung.httpclient.HttpClientExample

core-java-9/src/modules/com.baeldung.httpclient/com/baeldung/httpclient/HttpClientExample.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,22 +28,23 @@ public class HttpClientExample {
2828

2929
public static void main(String[] args) throws Exception {
3030
httpGetRequest();
31-
httpPosttRequest();
31+
httpPostRequest();
3232
asynchronousRequest();
3333
asynchronousMultipleRequests();
3434
}
3535

3636
public static void httpGetRequest() throws URISyntaxException, IOException, InterruptedException {
3737
HttpClient client = HttpClient.newHttpClient();
3838
URI httpURI = new URI("http://jsonplaceholder.typicode.com/posts/1");
39-
HttpRequest request = HttpRequest.newBuilder(httpURI).GET().build();
39+
HttpRequest request = HttpRequest.newBuilder(httpURI).GET()
40+
.headers("Accept-Enconding", "gzip, deflate").build();
4041
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandler.asString());
4142
String responseBody = response.body();
4243
int responseStatusCode = response.statusCode();
4344
System.out.println(responseBody);
4445
}
4546

46-
public static void httpPosttRequest() throws URISyntaxException, IOException, InterruptedException {
47+
public static void httpPostRequest() throws URISyntaxException, IOException, InterruptedException {
4748
HttpClient client = HttpClient
4849
.newBuilder()
4950
.build();

0 commit comments

Comments
 (0)