Created
January 19, 2013 17:12
-
-
Save onozaty/4573720 to your computer and use it in GitHub Desktop.
Google URL Shortener
using HttpClient(http://hc.apache.org/httpcomponents-client-ga/)
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
HttpPost post = new HttpPost("https://www.googleapis.com/urlshortener/v1/url?key={your API Key}"); | |
post.setHeader("Content-Type", "application/json"); | |
post.setEntity(new StringEntity("{'longUrl': 'http://www.google.com/'}", "UTF-8")); | |
HttpResponse response = new DefaultHttpClient().execute(post); | |
String responseText = EntityUtils.toString(response.getEntity()); | |
System.out.print(responseText); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment