Groovy: timeout due to lack of proxy server (java.net.ConnectException)

I want to use a Groovy script to access a webpage. However, I am for the proxy.

Here's a test script that fails ...

println "Google page is..." println 'http://www.google.com'.toURL().text 

Here's the conclusion ...

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

How to set proxy information in Groovy?

+4
source share
2 answers

Or, from within Groovy:

 System.properties << [ 'http.proxyHost':'proxyHost', 'http.proxyPort':'port' ] 
+11
source

Proxy information can be set for the JVM by passing arguments to the groovy command line, for example ...

groovy - Dhttp.proxyHost = proxyHost - Dhttp.proxyPort = Port number proxytester.groovy

This script then works ...

 println "Google page is..." println 'http://www.google.com'.toURL().text 

Here are the results ...

 Google page is <!doctype html><html itemscope itemtype="http://schema.org/WebPage"><head><meta http-equiv="content-type..... 

See the Oracle docs for more information.

+3
source

Source: https://habr.com/ru/post/1414361/


All Articles