>  Q&A  >  본문

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

      }

    怪我咯怪我咯2722일 전697

    모든 응답(0)나는 대답할 것이다

    답장 없음
  • 취소회신하다