1

我总是收到“连接到 ${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:05,950 [http-bio-8080-exec-6] 错误错误。GrailsExceptionResolver - 处理请求时发生 ConnectException:[GET] /CopperApplications/urlTracker 连接超时:连接。Stacktrace 如下:消息:连接超时:连接

4

1 回答 1

0

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

于 2012-08-14T07:31:38.313 回答