Ant 中有没有办法(使用 Groovy?)将信息发布到 http URL,然后解析响应? [英] Is there a way in Ant (using Groovy?) to post info to an http URL and then parse the response?

查看:18
本文介绍了Ant 中有没有办法(使用 Groovy?)将信息发布到 http URL,然后解析响应?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我找到了一种使用 Groovy + HTMLCleaner 在 Ant 中读取 HTML 页面的方法(请参阅:使用 Ant 脚本解析 HTML )但我无法找到一种方法来首先将一些数据发布到 URL,然后获得响应并能够使用 HTMLCleaner(或类似的东西)解析它).这可能吗?

I've found a way to read an HTML page in Ant with Groovy + HTMLCleaner (see: Parse HTML using with an Ant Script ) but I am unable to find a way to first POST some data to a URL and then get a response and be able to parse that with HTMLCleaner (or something similar). Is this posible?

推荐答案

您可以使用 groovy REST 客户端,它是 HTTPBuilder 项目的一部分.

You can use the groovy REST client, which is part of the HTTPBuilder project.

<target name="invoke-webservice">
    <taskdef name="groovy" classname="org.codehaus.groovy.ant.Groovy" classpathref="build.path"/>

    <groovy>
        import groovyx.net.http.RESTClient
        import groovy.util.slurpersupport.GPathResult
        import static groovyx.net.http.ContentType.URLENC

        def twitter = new RESTClient( 'https://twitter.com/statuses/' )

        def resp = twitter.post( path : 'update.xml',
                 body : [ status:msg, source:'httpbuilder' ],
                 requestContentType : URLENC )

        log.info "response status: ${resp.status}"
    </groovy>
</target>

这篇关于Ant 中有没有办法(使用 Groovy?)将信息发布到 http URL,然后解析响应?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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