Skip to content

Instantly share code, notes, and snippets.

@hlzhang
Created April 13, 2019 14:26
Show Gist options
  • Save hlzhang/1a58fe4b5e643d1821d27442e0a3c0f0 to your computer and use it in GitHub Desktop.
Save hlzhang/1a58fe4b5e643d1821d27442e0a3c0f0 to your computer and use it in GitHub Desktop.
Send http request in java11 jshell
// 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