File tree Expand file tree Collapse file tree
src/modules/com.baeldung.httpclient/com/baeldung/httpclient Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ java --module-path mods -m com.baeldung.httpclient/com.baeldung.httpclient.HttpClientExample
Original file line number Diff line number Diff 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 ();
You can’t perform that action at this time.
0 commit comments