Groovy:意外令牌:连接@行10

时间:2019-02-07 09:03:44

标签: groovy

我正在尝试使用groovy脚本更改Channel的状态。 为此,我需要执行URL,然后更改我的频道状态。

但是,在编写代码Eclipse后,在Line Connection上显示错误。 我是groovy的新手,请帮助解决此问题。

代码-

class startChannel {


    def url = new URL("http://XXXXXX&action=**STOP**")
    HttpURLConnection connection = (HttpURLConnection) url.openConnection();
    connection.setRequestMethod("POST")
    // connection.setConnectTimeout(10000)
    connection.connect()
    if (connection.responseCode == 200 || connection.responseCode == 201) {
        def returnMessage = connection.content
    } 
}

错误-

1. Description  Resource    Path    Location    Type
Groovy:expecting EOF, found 'if' @ line 11, column 2.   startChannel.groovy /GroovyTest/src line 11 Java Problem
2. Description  Resource    Path    Location    Type
Groovy:unexpected token: connection @ line 10, column 2.    startChannel.groovy /GroovyTest/src line 10 Java Problem
3. Description  Resource    Path    Location    Type
Groovy:unexpected token: connection @ line 8, column 2. startChannel.groovy /GroovyTest/src line 8  Java Problem
4. Description  Resource    Path    Location    Type
Groovy:unexpected token: if @ line 11, column 2.    startChannel.groovy /GroovyTest/src line 11 Java Problem

BR, 拉什米

1 个答案:

答案 0 :(得分:0)

删除课程。只需按照您说的那样执行主要步骤即可。

def url = new URL("http://XXXXXX&action=**STOP**")
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("POST")
// connection.setConnectTimeout(10000)
connection.connect()
if (connection.responseCode == 200 || connection.responseCode == 201) {
    def returnMessage = connection.content
} 

我建议您在http://groovy-lang.org/documentation.html中学习groovy的基础知识。