Сократить URL-адрес, используя Goo.gl здесь данные json отправляются в HTTP-заголовке в качестве почтового запроса.
переменного отправить с помощью перенаправления метода URL-адреса в longUrl
{'longUrl': 'https://www.google.com'}
это loginUrl высылаются как запрос поста в заголовке HTTP и google.com, наконец, создан как сокращенная URL.
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());
}
Этот результат содержит JSON в формате, как это:
{ "kind": "urlshortener#url", "id": "YourShorternURL", "longUrl": "https://www.google.com"}
Ваш URL Сокращенно является параметр "идентификатор" в формате JSON.
http://adityagoyal-java.blogspot.in/2016/09/shorten-url-using-googl-by-http-post.html