| | |
| | | import org.apache.http.util.EntityUtils;
|
| | | import org.yeshi.utils.entity.ProxyIP;
|
| | |
|
| | | import net.sf.json.JSONArray;
|
| | | import net.sf.json.JSONObject;
|
| | |
|
| | | public class HttpUtil {
|
| | |
| | | }
|
| | |
|
| | | public static String getShortLink(String url) {
|
| | | return url;
|
| | | // String shortLink = getShortLink3(url);
|
| | | // if (StringUtil.isNullOrEmpty(shortLink))
|
| | | // shortLink = getShortLink1(url);
|
| | | // if (StringUtil.isNullOrEmpty(shortLink))
|
| | | // shortLink = getShortLink2(url);
|
| | | // return shortLink;
|
| | | // return url;
|
| | | String shortLink = getShortLink3(url);
|
| | | if (StringUtil.isNullOrEmpty(shortLink))
|
| | | shortLink = getShortLink1(url);
|
| | | if (StringUtil.isNullOrEmpty(shortLink))
|
| | | shortLink = getShortLink2(url);
|
| | | return shortLink;
|
| | | }
|
| | |
|
| | | private static String getShortLink1(String url) {
|
| | |
| | |
|
| | | private static String getShortLink3(String url) {
|
| | | try {
|
| | | String totalUrl = String.format(
|
| | | "http://api.ft12.com/api.php?format=json&url=%s&apikey=Lqh4eXURkvKhbboXwz@ddd",
|
| | | String totalUrl = String.format("http://h5.flq001.com/short/createShort?url=%s",
|
| | | URLEncoder.encode(url, "UTF-8"));
|
| | | String result = get(totalUrl, null);
|
| | | JSONObject data = JSONObject.fromObject(result);
|
| | | return data.optString("url");
|
| | | return data.optString("short_url");
|
| | | } catch (Exception e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | |
| | |
|
| | | return result;
|
| | | }
|
| | | |
| | | |
| | | |
| | | /**
|
| | | * 获取post返回location
|
| | | * @param url
|
| | | * @return
|
| | | */
|
| | | public static String getLocation(String url) {
|
| | | HttpClient client = new HttpClient();
|
| | | PostMethod method = new PostMethod(url);
|
| | | try {
|
| | | client.executeMethod(method);
|
| | | return method.getResponseHeader("location").getValue();
|
| | | } catch (HttpException e) {
|
| | | e.printStackTrace();
|
| | | } catch (IOException e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | | return null;
|
| | | }
|
| | | }
|