※ 本文轉寄自 tomin.bbs@tomin.twbbs.org
標題 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
--
--
看板 coding
作者 標題 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
回列表(←)
分享