我总是收到“连接到${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 -处理请求时出现连接异常:[GET] /CopperApplications/urlTracker连接超时:连接。堆栈跟踪如下:消息:连接超时:连接
1条答案
按热度按时间wgx48brx1#
您的代码看起来是正确的,并且在Groovy 1.7.9和1.6.0_33 JVM上产生了预期的(?)结果。您的网络可能有问题(如连接超时错误所示)。