Groovy:由于未设置代理而超时(java.net.ConnectException)
我想使用Groovy脚本访问网页。但是我支持一个代理 这是一个失败的测试脚本Groovy:由于未设置代理而超时(java.net.ConnectException),groovy,proxy,Groovy,Proxy,我想使用Groovy脚本访问网页。但是我支持一个代理 这是一个失败的测试脚本 println "Google page is..." println 'http://www.google.com'.toURL().text 这是输出 >groovy proxytester.groovy Google page is... Caught: java.net.ConnectException: Connection timed out: connect at checker.run
println "Google page is..."
println 'http://www.google.com'.toURL().text
这是输出
>groovy proxytester.groovy
Google page is...
Caught: java.net.ConnectException: Connection timed out: connect
at checker.run(proxytester.groovy:2)
如何在Groovy中设置代理服务器信息?可以通过在Groovy命令行上传递参数为JVM设置代理信息,例如 groovy-Dhttp.proxyHost=proxyHost-Dhttp.proxyPort=端口号proxytester.groovy 这个脚本然后工作
println "Google page is..."
println 'http://www.google.com'.toURL().text
这是结果
Google page is
<!doctype html><html itemscope itemtype="http://schema.org/WebPage"><head><meta
http-equiv="content-type.....
Google页面是
或者,从Groovy本身内部:
System.properties << [ 'http.proxyHost':'proxyHost', 'http.proxyPort':'port' ]
System.properties