, 당신은 무엇을 Joachim suggests 수행하여 할 수있는 :
을 : 당신이 리디렉션하려면, 첫 페이지의 내용을 원하지 않는 경우
String location = "url-of-webpage-A"
boolean wasRedirected = false
String pageContent = null
while(location) {
new URL(location).openConnection().with { con ->
// We'll do redirects ourselves
con.instanceFollowRedirects = false
// Get the response code, and the location to jump to (in case of a redirect)
location = con.getHeaderField("Location")
if(!wasRedirected && location) {
wasRedirected = true
}
// Read the HTML and close the inputstream
pageContent = con.inputStream.withReader { it.text }
}
}
println "wasRedirected:$wasRedirected contentLength:${pageContent.length()}"
, 당신은 간단하게 할 필요가
String location = "url-of-webpage-A"
String pageContent = new URL(location).openConnection().with { con ->
// We'll do redirects ourselves
con.instanceFollowRedirects = false
// Get the location to jump to (in case of a redirect)
location = con.getHeaderField("Location")
// Read the HTML and close the inputstream
con.inputStream.withReader { it.text }
}
if(location) {
println "Page wanted to redirect to $location"
}
println "Content was:"
println pageContent
안녕하세요 팀, 나는 위의 코드를 시도했지만 여전히 새로운 위치/리디렉션 된 웹 페이지의 내용을 검색합니다. :(원본 페이지의 내용이 필요합니다. –
@VeeKay 오 ... 최종 페이지의 내용을 원했지만 리디렉션되었음을 알았습니다 ... 희망하는 일을하기 위해 다른 방법을 추가했습니다. 당신이 원했던 ... –