| | |
| | | import java.net.MalformedURLException;
|
| | | import java.net.URL;
|
| | | import java.net.URLEncoder;
|
| | | import java.util.ArrayList;
|
| | | import java.util.Iterator;
|
| | | import java.util.List;
|
| | | import java.util.Map;
|
| | |
|
| | | import org.apache.commons.httpclient.Header;
|
| | |
| | | import org.apache.http.auth.UsernamePasswordCredentials;
|
| | | import org.apache.http.client.CredentialsProvider;
|
| | | import org.apache.http.client.config.RequestConfig;
|
| | | import org.apache.http.client.entity.UrlEncodedFormEntity;
|
| | | import org.apache.http.client.methods.CloseableHttpResponse;
|
| | | import org.apache.http.client.methods.HttpPost;
|
| | | import org.apache.http.impl.client.BasicCredentialsProvider;
|
| | |
| | | import org.apache.http.impl.client.HttpClients;
|
| | | import org.apache.http.util.EntityUtils;
|
| | | import org.yeshi.utils.entity.ProxyIP;
|
| | |
|
| | | import net.sf.json.JSONArray;
|
| | |
|
| | | public class HttpUtil {
|
| | |
|
| | |
| | | }
|
| | |
|
| | | public static String getShortLink(String url) {
|
| | | String totalUrl = String.format("http://api.t.sina.com.cn/short_url/shorten.json?source=3271760578&url_long=%s",
|
| | | URLEncoder.encode(url));
|
| | | String result = get(totalUrl, null);
|
| | | JSONArray rtesultArray = JSONArray.fromObject(result);
|
| | | if (rtesultArray.size() > 0) {
|
| | | return rtesultArray.optJSONObject(0).optString("url_short");
|
| | | try {
|
| | | String totalUrl = String.format("http://api.suolink.cn/api.php?url=%s", URLEncoder.encode(url));
|
| | | String result = get(totalUrl, null);
|
| | | if (!StringUtil.isNullOrEmpty(result) && result.startsWith("http"))
|
| | | return result.trim();
|
| | |
|
| | | // JSONArray rtesultArray = JSONArray.fromObject(result);
|
| | | // if (rtesultArray.size() > 0) {
|
| | | // return rtesultArray.optJSONObject(0).optString("url_short");
|
| | | // }
|
| | | } catch (Exception e) {
|
| | | return url;
|
| | | }
|
| | | return null;
|
| | | }
|