2015-11-28 54 views
0

我向Android請求Grails控制器。 請求更改數據庫中的數據,但Grails的服務器返回一個錯誤:Grails HTTBuilder請求錯誤

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

您將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 
    } 
}