开发者

Grails REST Client Plugin - PUT body content

开发者 https://www.devze.com 2023-02-19 01:26 出处:网络
Documentation seems to be lacking on both the plugin side as well as the HTTPBuilder side of things.I\'m trying to submit some json through the put method, but it keeps telling me that put() doesn\'t

Documentation seems to be lacking on both the plugin side as well as the HTTPBuilder side of things. I'm trying to submit some json through the put method, but it keeps telling me that put() doesn't like the map I am feeding it.

Does anyone have an example of a PUT using the Grails REST Client plugin? Here is what I've tried:

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

        def json 开发者_高级运维= put(body: bodyContent)

        if (json.stat == 'ok') {
          wsr.success = true
        }
}

Error:

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"
    }
  ]]


HTTPBuilder doesn't have a put method. Try changing withHttp to withRest so that your statements are executed with the RESTClient. Also, I think by default the body is encoded as URL encoded, so you might need to specify requestContentType: groovyx.net.http.ContentType.JSON as another parameter to your 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
        }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消