public static String generateShortUrl(String url) {
try {
HttpPost httpost = new HttpPost("http://dwz.cn/create.php");
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("url", url)); // 用户名称
httpost.setEntity(new UrlEncodedFormEntity(params, "utf-8"));
HttpResponse response = httpclient.execute(httpost);
String jsonStr = EntityUtils.toString(response.getEntity(), "utf-8");
JSONObject object = JSON.parseObject(jsonStr);
return object.getString("tinyurl");
} catch (Exception e) {
e.printStackTrace();
return "Error";
}
}