2012-03-14 1 views
1

Groovy + HTMLCleaner (참조 : Parse HTML using with an Ant Script)로 Ant에서 HTML 페이지를 읽는 방법을 찾았지만 URL에 일부 데이터를 먼저 POST 한 다음 응답을 받고 구문 분석 할 수있는 방법을 찾을 수 없습니다. 그 HTMLCleaner (또는 비슷한). 이게 가능한가?Ant (Groovy 사용?)에서 http URL에 정보를 게시 한 다음 응답을 구문 분석 할 수 있습니까?

+1

개미의 임무 작업을 사용하면 ctsrl을 사용할 수 있습니다. http://superuser.com/questions/149329/how-do-i-make-a-post-request-with-the-curl-command-line-tool –

+0

을 참조하십시오. 그런 다음 어떻게 응답을 구문 분석합니까? 나는 특히 DOM을 순회하는 HTMLCleaner처럼 깨끗해야한다. –

답변

2

HTTPBuilder 프로젝트의 일부인 그루비 REST client을 사용할 수 있습니다.

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