URL mit Goo.gl verkürzen hier Json Daten senden in http-Header als Post-Anfrage.
send Variable durch URL-Methode in longUrl mit umleiten
{'longUrl': 'https://www.google.com'}
diese loginUrl ist als Post-Anforderung in HTTP-Header senden und google.com wird schließlich als shorten url erstellt.
public void sendPostBody() throws Exception {
String url = "https://www.googleapis.com/urlshortener/v1/url?key=YOUR_GENERATED_KEY"; //Generated your own key on your google account
HttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost(url);
// add header
post.setHeader("Content-type","application/json");
post.setEntity(new StringEntity("{'longUrl': 'https://www.google.com'}", "UTF8"));
HttpResponse response = client.execute(post);
BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
StringBuffer result = new StringBuffer();
String line = "";
while ((line = rd.readLine()) != null) {
result.append(line);
}
System.out.println(" The shorten Goo.gl Url is :::: "+result.toString());
}
Dieses Ergebnis enthält eine json im Format wie folgt aus:
{ "kind": "urlshortener#url", "id": "YourShorternURL", "longUrl": "https://www.google.com"}
Ihre Shorten URL ist die "id" Parameter in der JSON.
Quelle: http://adityagoyal-java.blogspot.in/2016/09/shorten-url-using-googl-by-http-post.html