Groovy中HttpURLConnection的连接超时 [英] Connection timeout with HttpURLConnection in Groovy

查看:777
本文介绍了Groovy中HttpURLConnection的连接超时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



任何人都可以向我展示我的错误吗?

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

//打印完整回复
println returnMessage
} else {
println错误连接到+ url
}

错误2012-07-05 00:04:05,950 [http-bio-8080-exec-6] ERROR errors.GrailsExceptionResolver - 处理请求时发生ConnectException:[GET] / CopperApplications / urlTracker连接超时:连接。 Stacktrace如下:消息:连接超时:connec

解决方案

您的代码看起来正确,并在Groovy上产生预期的1.7.9与1.6.0_33 JVM。您的网络可能存在某些问题(如连接超时错误所示)。


I am always getting the "Error Connecting to ${url}" message?

Can anyone please show me my mistake?

        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
        }

| Error 2012-07-05 00:04:05,950 [http-bio-8080-exec-6] ERROR errors.GrailsExceptionResolver - ConnectException occurred when processing request: [GET] /CopperApplications/urlTracker Connection timed out: connect. Stacktrace follows: Message: Connection timed out: connec

解决方案

Your code seems correct, and produces the expected(?) results on Groovy 1.7.9 with 1.6.0_33 JVM. There is likely something amiss with your network (as indicated by the connection timeout error).

这篇关于Groovy中HttpURLConnection的连接超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆