Groovy中HttpURLConnection的连接超时

Groovy中HttpURLConnection的连接超时,url,groovy,Url,Groovy,我总是收到“连接到${url}时出错”消息 谁能告诉我我的错误吗 def url = new URL("https://www.google.com") HttpURLConnection connection = (HttpURLConnection) url.openConnection() connection.setRequestMethod("GET") // connection.setConnectTimeout(10

我总是收到“连接到${url}时出错”消息

谁能告诉我我的错误吗

        def url = new URL("https://www.google.com")
        HttpURLConnection connection = (HttpURLConnection) url.openConnection()
        connection.setRequestMethod("GET")
        // connection.setConnectTimeout(10000)
        connection.connect()
        if (connection.responseCode == 200 || connection.responseCode == 201) {
            def returnMessage = connection.content

            //print out the full response
            println returnMessage
        } else {
            println "Error Connecting to " + url
        }

|错误2012-07-05 00:04:05950[http-bio-8080-exec-6]错误。GrailExceptionResolver-处理请求[GET]/CopperApplications/urlTracker连接超时:连接时发生连接异常。Stacktrace如下:Message:Connection timed out:connec

您的代码似乎是正确的,并在带有1.6.0!JVM的Groovy 1.7.9上生成了预期的(?)结果。您的网络可能有问题(如连接超时错误所示)。

您实际得到的是什么
responseCode
?这将是解决此问题的有用信息。|错误2012-07-05 00:04:05950[http-bio-8080-exec-6]错误。GrailExceptionResolver-处理请求[GET]/CopperApplications/urlTracker连接超时:connect时发生连接异常。Stacktrace如下:消息:连接超时:connect@sam1132-请编辑您的问题,包括该错误消息。它对试图回答你的问题的人很有用,应该是问题的一部分,而不仅仅是在评论中。你用不同的URL尝试过吗?包括非HTTPS URL?是的,我使用了http,也很少使用内部站点,我总是遇到超时错误