Created
April 13, 2019 14:26
-
-
Save hlzhang/1a58fe4b5e643d1821d27442e0a3c0f0 to your computer and use it in GitHub Desktop.
Send http request in java11 jshell
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// jshell -v --add-modules=java.net.http http_request.jsh | |
import java.net.*; | |
import java.net.http.*; | |
HttpClient httpClient = HttpClient.newHttpClient(); | |
HttpRequest httpRequest = HttpRequest.newBuilder().uri(new URI("https://graph.facebook.com/v2.9/me?fields=id,email,cover,first_name,gender,last_name,link,locale,name,timezone,updated_time,verified,friends&access_token=change_it&appsecret_proof=change_it&method=get&format=json")).GET().build(); | |
HttpResponse<String> httpResponse = httpClient.send(httpRequest, HttpResponse.BodyHandlers.ofString()); | |
System.out.println(httpResponse.statusCode()); | |
System.out.println(httpResponse.body()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment