Skip to content

Instantly share code, notes, and snippets.

@onozaty
Created January 19, 2013 17:12
Show Gist options
  • Save onozaty/4573720 to your computer and use it in GitHub Desktop.
Save onozaty/4573720 to your computer and use it in GitHub Desktop.
Google URL Shortener using HttpClient(http://hc.apache.org/httpcomponents-client-ga/)
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