Created
April 13, 2016 06:39
-
-
Save zinking/02381fd9e7a6dc2694733572599a53d7 to your computer and use it in GitHub Desktop.
Java Apache HttpClient make request
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
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