Grails REST客户端插件 - PUT正文内容

Gre*_*egg 2 rest grails grails-plugin httpbuilder

插件方面以及HTTPBuilder方面的文档似乎都缺乏.我试图通过put方法提交一些json,但它一直告诉我put()不喜欢我正在喂它的地图.

有没有人使用Grails REST Client插件有一个PUT的例子?这是我尝试过的:

withHttp(uri: "http://foo/doo/roo") {
        def bodyContent = [
            pano: jsonText
        ]

        def json = put(body: bodyContent)

        if (json.stat == 'ok') {
          wsr.success = true
        }
}
Run Code Online (Sandbox Code Playgroud)

错误:

No signature of method: com.wbr.pano.PanService.put() is applicable for argument types: (java.util.LinkedHashMap) values: [[body:
    {
      "class":"com.wbr.platform.Pano",
      "errorMessage":"null",
      "imageSize":0,
      "id":26,
      "completed":"2011-03-20 3:50:27.257",
      "downloading":"2011-03-20 3:49:12.269",
      "processing":"2011-03-20 3:49:42.911",
      "uploading":"2011-03-20 3:50:12.107"
    }
  ]]
Run Code Online (Sandbox Code Playgroud)

Joh*_*ner 6

HTTPBuilder没有put方法.尝试将withHttp更改为withRest,以便使用RESTClient执行语句.此外,我认为默认情况下,正文被编码为URL编码,因此您可能需要指定requestContentType:groovyx.net.http.ContentType.JSON作为您的put的另一个参数.

import static groovyx.net.http.ContentType.*

withRest(uri: "http://foo/doo/roo") {
        def bodyContent = [
            pano: jsonText
        ]

        def json = put(body: bodyContent, requestContentType: JSON)

        if (json.status == 200) {
          wsr.success = true
        }
}
Run Code Online (Sandbox Code Playgroud)