public String getShortUrl(String urlToShort){
String apiUrl = "http://is.gd/api.php?longurl=" + urlToShort;
String ret = "";
HttpClient httpclient = new DefaultHttpClient();
HttpResponse response;
try {
response = httpclient.execute(new HttpGet(apiUrl));
InputStream is = response.getEntity().getContent();
if (is != null) {
StringBuilder sb = new StringBuilder();
String line;
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(is, "UTF-8"));
while ((line = reader.readLine()) != null) {
sb.append(line);
}
} finally {
is.close();
}
ret = sb.toString();
}
} catch (ClientProtocolException e) {
Log.e("Error", "Error: " + e.getMessage());
} catch (IOException e) {
Log.e("Error", "Error: " + e.getMessage());
}
return ret;
}
miércoles, 5 de mayo de 2010
Snippet: Short an URL using http://is.gd/
Suscribirse a:
Entradas (Atom)