String shareUrl = "http://www.baidu.com/";
RestTemplate template = new RestTemplate();
//百度短地址服务
String url = "http://dwz.cn/create.php";
LinkedMultiValueMap<String, Object> parts = new LinkedMultiValueMap<String, Object>();
parts.add("url", shareUrl);
String result = template
.postForObject(url, parts, String.class);
JSONObject jsonObject = JSONObject.fromString(result);
if (jsonObject.getInt("status") == 0
&& jsonObject.containsKey("tinyurl")) {
shareUrl = jsonObject.getString("tinyurl");
}
时间: 2024-10-02 08:49:09