Created
November 29, 2012 23:20
-
-
Save bryanchug/4172603 to your computer and use it in GitHub Desktop.
HTTPBuilder with Proxy
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
@Grapes( | |
@Grab(group='org.codehaus.groovy', module='http-builder', version='0.4.1') | |
) | |
import groovyx.net.http.* | |
import static groovyx.net.http.ContentType.* | |
import static groovyx.net.http.Method.* | |
import org.apache.http.auth.* | |
def http = new HTTPBuilder( 'http://www.ipchicken.com' ) | |
http.client.getCredentialsProvider().setCredentials( | |
new AuthScope("myproxy.com", 8080), | |
new UsernamePasswordCredentials("proxy-username", "proxy-password") | |
) | |
http.setProxy('myproxy.com', 8080, 'http') | |
http.request( GET, TEXT ){ req -> | |
response.success = { resp, reader -> | |
println "Response: ${reader.text}" | |
} | |
} |
Why can't the proxy settings default to the Java system property values? I don't want to be changing my code based on whether or not I am running behind a proxy.
will it work in conjunction with my provider advanced.name/ru ?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The first time is to associate the credentials with that url (most likely the proxy will send a 401 which can be automatically responded to with the stored credentials). The second time to declare the proxy coordinates itself.