如何获取搜狗微信的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();
         }

      }

    阅读 3.2k
    撰写回答
    你尚未登录,登录后可以
    • 和开发者交流问题的细节
    • 关注并接收问题和回答的更新提醒
    • 参与内容的编辑和改进,让解决方法与时俱进
    推荐问题