Grails HTTBuilder请求错误

时间:2015-11-28 16:29:36

标签: grails httpbuilder

我从Android向Grails控制器发出请求。 请求更改数据库中的数据,但Grails服务器返回错误:

2015-11-28 19:23:31,973 [http-bio-8080-exec-5] ERROR errors.GrailsExceptionResolver  - MissingPropertyException occurred when processing request: [POST] /ServerReg/saveReg/regSave
No such property: success for class: org.apache.catalina.connector.ResponseFacade. Stacktrace follows:
Message: No such property: success for class: org.apache.catalina.connector.ResponseFacade

我的Grails控制器:

def saveRegLink = new HTTPBuilder("http://db.likepay.me:80/rest/checkReg/registration/?fields=id");
saveRegLink.request(POST, JSON) { req ->
    headers.'X-DreamFactory-Session-Token' = session_id
    headers.'X-DreamFactory-Application-Name' = serviceName
    body = [
        telNum: telNum,
        IMEI: IMEI,
        DeviceName: DeviceName,
        SIM_SN: SIM_SN
    ]
}
response.success = {resp, json ->
    println resp.status
    render json
    return json
}
response.failure = { resp ->
    println 'request failed'
    assert resp.status >= 400
}

我将非常感谢你的帮助。

1 个答案:

答案 0 :(得分:1)

您在闭包之外的response.success / response.failure范围内传递给request方法。

它应该是这样的:

def saveRegLink = new HTTPBuilder("http://db.likepay.me:80/rest/checkReg/registration/?fields=id");
saveRegLink.request(POST, JSON) { req ->
    headers.'X-DreamFactory-Session-Token' = session_id
    headers.'X-DreamFactory-Application-Name' = serviceName
    body = [
        telNum: telNum,
        IMEI: IMEI,
        DeviceName: DeviceName,
        SIM_SN: SIM_SN
    ]

    response.success = {resp, json ->
        println resp.status
        render json
        return json
    }
    response.failure = { resp ->
        println 'request failed'
        assert resp.status >= 400
    }   
}