public final class HttpClientMethods extends Object
This utility class provides one-liner methods for HTTP related operations.
HTTP (Hypertext Transfer Protocol) is the set of rules for transferring files on the World Wide Web. Makes it easy to execute HTTP requests (GET/POST) and returns response message entity content as String.
Modifier and Type | Method and Description |
---|---|
static String |
http(String uri)
Send a HTTP GET Request
|
static String |
http(String uri,
Closure<String> body)
Send a HTTP POST Request
|
static String |
http(String uri,
Map params)
Send a HTTP Request
|
static String |
http(String uri,
Map params,
Map headers)
Send a HTTP Request
|
static String |
http(String uri,
Map params,
Map headers,
byte[] body)
Send a HTTP Request
|
static String |
http(String uri,
Map params,
Map headers,
Closure<String> body)
Send a HTTP Request
|
static String |
http(String uri,
Map params,
Map headers,
String body)
Send a HTTP Request
|
static String |
http(String uri,
String body)
Send a HTTP POST Request
|
public static String http(String uri) throws ToroException
Send a HTTP GET Request
Example Usage:
def messageEntity = 'http://wsf.cdyne.com/WeatherWS/Weather.asmx'.http()
uri
- The uri to requestToroException
public static String http(String uri, String body) throws ToroException
Send a HTTP POST Request
Example Usage:
def response = "http://www.example.com".http("Hello World ")
uri
- The uri to requestbody
- The body content in String for the requestToroException
public static String http(String uri, Closure<String> body) throws ToroException
Send a HTTP POST Request
Example Usage:
boolean success = false; def response = "http://www.example.com".http(){ if(success) "Successful" //This returns the string even without the keyword return else "Failed to Authenticate" }
uri
- The uri to requestbody
- The body content in Closure of return type String for the requestToroException
public static String http(String uri, Map params) throws ToroException
Send a HTTP Request
Example Usage:
def properties = [ method: "POST", email : "yourEmail@example.com", password : "helloWorld" ] def response = "https://www.example.com/login".http ( properties )
uri
- The uri to requestparams
- Optional properties for requestToroException
public static String http(String uri, Map params, Map headers) throws ToroException
Send a HTTP Request
Example Usage:
def properties = [ method: "POST", email : "yourEmail@example.com", password : "helloWorld" ] def header = [ "Content-Type" : "text/xml", "Connection" : "keep-alive" ] def response = "https://www.example.com/login".http ( properties, header )
uri
- The uri to requestparams
- Optional properties for requestheaders
- Optional header for requestToroException
public static String http(String uri, Map params, Map headers, String body) throws ToroException
Send a HTTP Request
Example Usage:
def properties = [ method: "POST", email : "yourEmail@example.com", password : "helloWorld" ] def header = [ "Content-Type" : "text/xml", "Connection" : "keep-alive" ] def response = "https://www.example.com/login".http ( properties, header, "Hello World " )
uri
- The uri to requestparams
- Optional properties for requestheaders
- Optional header for requestbody
- The body content in String for the requestToroException
public static String http(String uri, Map params, Map headers, Closure<String> body) throws ToroException
Send a HTTP Request
Example Usage:
def properties = [ method: "POST", email : "yourEmail@example.com", password : "helloWorld" ] def header = [ "Content-Type" : "text/xml", "Connection" : "keep-alive" ] boolean success = header != null def response = "https://www.example.com/login".http ( properties, header, { if( success ) "Successful" //This returns the string even without the keyword return else "Failed to Authenticate" } )
uri
- The uri to requestbody
- The body content in Closure of return type String content for the requestparams
- Optional properties for requestheaders
- Optional header for requestToroException
public static String http(String uri, Map params, Map headers, byte[] body) throws ToroException
Send a HTTP Request
Example Usage:
def properties = [ method: "POST", email : "yourEmail@example.com", password : "helloWorld" ] def header = [ "Content-Type" : "text/xml", "Connection" : "keep-alive" ] def body = "This is an example body in bytes" def response = "https://www.example.com/login".http ( properties, header, body.getBytes() )
uri
- The uri to requestbody
- The body content in bytes for the requestparams
- Optional properties for requestheaders
- Optional header for requestToroException
Copyright © 2019. All rights reserved.