Skip to content

Commit

Permalink
add headers ex
Browse files Browse the repository at this point in the history
  • Loading branch information
lor6 committed Dec 1, 2017
1 parent d4715a7 commit bdf8817
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
1 change: 1 addition & 0 deletions core-java-9/run-httpclient.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
java --module-path mods -m com.baeldung.httpclient/com.baeldung.httpclient.HttpClientExample
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,23 @@ public class HttpClientExample {

public static void main(String[] args) throws Exception {
httpGetRequest();
httpPosttRequest();
httpPostRequest();
asynchronousRequest();
asynchronousMultipleRequests();
}

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

public static void httpPosttRequest() throws URISyntaxException, IOException, InterruptedException {
public static void httpPostRequest() throws URISyntaxException, IOException, InterruptedException {
HttpClient client = HttpClient
.newBuilder()
.build();
Expand Down

0 comments on commit bdf8817

Please sign in to comment.