Question

Can we request a https link using HttpBuilder ?

1 - if yes then is their any specific parameters or properties we need to set while request the data.

2 - if not then can we request same as the normal http link as in the below e.g.

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'] )
Was it helpful?

Solution

Just tried it, and it does work as it says in the docs...

@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()
    }
  }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top