简体   繁体   中英

Using multiple http proxies in groovy

I need to use multiple http proxies in parallel in a groovy script. Eg

url1 = 'https://boston.myorg.com' 
proxy1 = 10.0.0.3:8000
url2 = 'https://newyork.myorg.com'
proxy2 = 10.0.0.5:8001

I have found examples like the one below, but wouldn't that set the proxy for every connection in the script? Is there a way to do this so that each connection uses it's own proxy?

System.properties.putAll( ["http.proxyHost":"proxy-host", "http.proxyPort":"proxy-port"] )  
    def url = 'http://www.google.com/images/logo.gif'  
    def file = new FileOutputStream(address.tokenize("/")[-1])  
    def out = new BufferedOutputStream(file)  
    out << new URL(address).openStream()  
    out.close() 

https://docs.oracle.com/javase/8/docs/technotes/guides/net/proxies.html

Proxy class section

SocketAddress proxy1Addr = new InetSocketAddress("10.0.0.3", 8000)
Proxy proxy1 = new Proxy(Proxy.Type.HTTP, proxy1Addr)

URL url1 = new URL("https://boston.myorg.com/")
URLConnection conn1 = url1.openConnection(proxy1)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM