HTTPBuilder HTTP Post url encoded parameters and accept xml response?

空扰寡人 提交于 2020-01-03 05:26:17

问题


Hi there i am wondering how i can post a urlencoded string and read in an xml response using HTTPBuilder? I would like to use this inside a Grails application. The REST plugin is no option. I tried the examples given on http://groovy.codehaus.org/modules/http-builder/doc/post.html but this gives me no xml response to read in.


回答1:


You can try something like this:

def httpBuilder = new HTTPBuilder("http://webite.url")

httpBuilder.request(Method.POST, URLENC){req->
    headers.accept = "application/xml"
    body = [ YOUR URL ENCODED POST]

    response.success = {resp,xml->
       //read xml response.
    }
}


来源:https://stackoverflow.com/questions/8719242/httpbuilder-http-post-url-encoded-parameters-and-accept-xml-response

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!