Is there a way in Ant (using Groovy?) to post info to an http URL and then parse the response?

时光总嘲笑我的痴心妄想 提交于 2019-12-13 02:25:29

问题


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?


回答1:


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>


来源:https://stackoverflow.com/questions/9708626/is-there-a-way-in-ant-using-groovy-to-post-info-to-an-http-url-and-then-parse

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