Skip to content

Instantly share code, notes, and snippets.

@zinking
Created April 13, 2016 06:39
Show Gist options
  • Save zinking/02381fd9e7a6dc2694733572599a53d7 to your computer and use it in GitHub Desktop.
Save zinking/02381fd9e7a6dc2694733572599a53d7 to your computer and use it in GitHub Desktop.
Java Apache HttpClient make request
public static String getAccessTokenOfAccount() throws IOException {
String url = "SOMEURL";
DefaultHttpClient client = new DefaultHttpClient();
HttpGet request = new HttpGet(url);
HttpResponse response = client.execute(request);
BufferedReader rd = new BufferedReader(
new InputStreamReader(response.getEntity().getContent()));
StringBuilder result = new StringBuilder();
String line = "";
while ((line = rd.readLine()) != null) {
result.append(line);
}
String responseJson = result.toString();
final ObjectMapper mapper = new ObjectMapper();
BingTokenResult tokenResult = mapper.readValue(responseJson, Result.class);
return tokenResult.getAccessToken();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment