Created
March 22, 2012 20:02
-
-
Save atbradley/2163004 to your computer and use it in GitHub Desktop.
Disable automatic redirect handling in HTTPBuilder
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Return the actual location of a web page given a shortened url. | |
// Based in part on this Stack Overflow answer: | |
// http://stackoverflow.com/questions/1519392/how-to-prevent-apache-http-client-from-following-a-redirect | |
import groovyx.net.http.HTTPBuilder | |
import org.apache.http.impl.client.AbstractHttpClient | |
import org.apache.http.params.BasicHttpParams | |
import static groovyx.net.http.Method.HEAD | |
HTTPBuilder http = new HTTPBuilder(url) | |
AbstractHttpClient ahc = http.client | |
BasicHttpParams params = new BasicHttpParams(); | |
params.setParameter("http.protocol.handle-redirects",false) | |
ahc.setParams(params) | |
http.request(HEAD) { | |
response.success = { rsp -> | |
println rsp.headers?.Location | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment