顯示廣告
隱藏 ✕
※ 本文轉寄自 tomin.bbs@tomin.twbbs.org
看板 coding
作者 tomin (科學大師、哲學博士)
標題 Detect URL redirect
時間 2011/02/28 Mon 16:35:34


http://stackoverflow.com/questions/251532/
how-can-i-determine-if-a-url-redirects

URL url = new URL ('http://google.com')
HttpURLConnection conn = url.openConnection()
conn.followRedirects = false
conn.requestMethod = 'HEAD'
println conn.responseCode
// Not ideal - should check response code too
if (conn.headerFields.'Location') {
  println conn.headerFields.'Location'
}

301
["http://www.google.com/"]


http://www.java-forums.org/new-java/23722-http-url-301-redirect.html

http://www.webconfs.com/how-to-redirect-a-webpage.php

http://en.wikipedia.org/wiki/URL_redirection

http://stackoverflow.com/questions/704956/
getting-the-redirected-url-from-the-original-url

--
  Origin:  Loess Plateau˙黃土高原  tomin.twbbs.org
  Author: tomin 從 tomin.mdorm.ntnu.edu.tw 發表


--
※ 看板: tomin 文章推薦值: 0 目前人氣: 0 累積人氣: 35 
guest
x)推文 r)回覆 e)編輯 d)刪除 M)收藏 ^x)轉錄 同主題: =)首篇 [)上篇 ])下篇