【发布时间】:2019-06-26 20:04:02
【问题描述】:
我需要在 groovy 脚本中并行使用多个 http 代理。例如
url1 = 'https://boston.myorg.com'
proxy1 = 10.0.0.3:8000
url2 = 'https://newyork.myorg.com'
proxy2 = 10.0.0.5:8001
我找到了像下面这样的示例,但是这不会为脚本中的每个连接设置代理吗?有没有办法让每个连接都使用自己的代理?
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()
【问题讨论】: