java - 如何获取搜狗微信的Url,准备进行重定向,但是不知道怎么办
怪我咯
怪我咯 2017-04-17 17:30:29
0
0
692
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();
         }

      }

    怪我咯
    怪我咯

    走同样的路,发现不同的人生

    Antworte allen(0)
    Beliebte Tutorials
    Mehr>
    Neueste Downloads
    Mehr>
    Web-Effekte
    Quellcode der Website
    Website-Materialien
    Frontend-Vorlage
    Über uns Haftungsausschluss Sitemap
    Chinesische PHP-Website:Online-PHP-Schulung für das Gemeinwohl,Helfen Sie PHP-Lernenden, sich schnell weiterzuentwickeln!