0

我们可以使用 HttpBuilder 请求 https 链接吗?

1 - 如果是,那么它们是我们在请求数据时需要设置的任何特定参数或属性。

2 - 如果不是,那么我们可以请求与下面的普通 http 链接相同的请求,例如

def http = new HTTPBuilder('http://some_link'); 
def resp = http.get(path: '/abcd/efg', query:[login:'login_id', pass: 'password',ttype:'trans_type',prodid:'prod_id'], contentType : XML, headers : [Accept : 'application/xml'] )
4

1 回答 1

1

刚刚尝试过,它确实像文档中所说的那样工作......

@Grab( 'org.ccil.cowan.tagsoup:tagsoup:1.2' )
@Grab( 'org.codehaus.groovy.modules.http-builder:http-builder:0.5.2' )
import org.ccil.cowan.tagsoup.Parser
import groovyx.net.http.HTTPBuilder
import static groovyx.net.http.ContentType.*

// Using an https url
new HTTPBuilder( 'https://twitter.com' ).with {
  // Get from the given path as TEXT
  get( path:'/tim_yates', contentType:TEXT ) { resp, reader ->
    // Pass the html through tagsoup and generate a parser
    new XmlParser( new Parser() ).parseText( reader.text ).with {
      // print the title text from inside the head section
      println head.title.text()
    }
  }
}
于 2012-07-19T12:59:19.413 回答