有没有(使用Groovy?)张贴到一个HTTP URL信息,然后解析响应以蚂蚁的方式? [英] Is there a way in Ant (using Groovy?) to post info to an http URL and then parse the response?

查看:242
本文介绍了有没有(使用Groovy?)张贴到一个HTTP URL信息,然后解析响应以蚂蚁的方式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经找到一种方法使用Groovy + HTMLCleaner(见读取蚂蚁的HTML页面的解析HTML与Ant脚本使用),但我无法找到一种方法,首先是一些POST数据到一个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?

推荐答案

您可以使用常规的 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>

这篇关于有没有(使用Groovy?)张贴到一个HTTP URL信息,然后解析响应以蚂蚁的方式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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