首页 > 如何获取搜狗微信的Url,准备进行重定向,但是不知道怎么办

如何获取搜狗微信的Url,准备进行重定向,但是不知道怎么办

public static void test_getRedirectUrl() throws Exception {
    String url = "http://weixin.sogou.com/websearch/art.jsp?sg=CBf80b2......";
    String redictURL = getRedirectUrl(url);
    System.out.println(redictURL);
}

/**
    • 获取重定向地址

    • @param path

    • @return

    • @throws Exception
      */

    1. static String getRedirectUrl(String path) throws Exception {

         HttpURLConnection conn = (HttpURLConnection) new URL(path)
                 .openConnection();
         conn.setInstanceFollowRedirects(false);
         conn.setConnectTimeout(5000);
         return conn.getHeaderField("Location");

      }

    2. static void main(String[] args) {

         try {
             test_getRedirectUrl();
         } catch (Exception e) {
             e.printStackTrace();
         }

      }

    【热门文章】
    【热门文章】