Groovy中HttpURLConnection的连接超时 [英] Connection timeout with HttpURLConnection in Groovy
问题描述
任何人都可以向我展示我的错误吗?
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屋!