HTTPBuilder HTTP发布url编码参数并接受xml响应? [英] HTTPBuilder HTTP Post url encoded parameters and accept xml response?

查看:116
本文介绍了HTTPBuilder HTTP发布url编码参数并接受xml响应?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我想知道如何发布urlencoded字符串并使用HTTPBuilder读取xml响应?我想在Grails应用程序中使用它。 REST插件是没有选择的。我尝试了 http://groovy.codehaus.org/modules上给出的示例/http-builder/doc/post.html ,但这不会让我读到xml响应。

您可以尝试如下所示:

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

httpBuilder.request(Method.POST,URLENC){req->
headers.accept =application / xml
body = [您的URL编码的邮件]

response.success = {resp,xml->
//读取xml响应。
}
}


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.

解决方案

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.
    }
}

这篇关于HTTPBuilder HTTP发布url编码参数并接受xml响应?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆