Groovy:由于未设置代理而导致超时(java.net.ConnectException)

Chr*_*ris 4 proxy groovy

我想使用Groovy脚本来访问网页.但是我支持代理.

这是一个失败的测试脚本......

println "Google page is..."
println 'http://www.google.com'.toURL().text
Run Code Online (Sandbox Code Playgroud)

这是输出......

>groovy proxytester.groovy 
Google page is... 
Caught: java.net.ConnectException: Connection timed out: connect
   at checker.run(proxytester.groovy:2)
Run Code Online (Sandbox Code Playgroud)

如何在Groovy中设置代理服务器信息?

tim*_*tes 11

或者,从Groovy内部:

System.properties << [ 'http.proxyHost':'proxyHost', 'http.proxyPort':'port' ]
Run Code Online (Sandbox Code Playgroud)