HttpRequestHelper
You can use the APIs defined in this utility class to execute HTTP requests.
HTTP GET
public static void get(
String uristr,
Map<String, String> headers,
Map<String, Object> params,
Map<String, Object> options,
Consumer<? super HttpResponse> action);
HTTP POST
public static void post(
String uristr,
Map<String, String> headers,
Map<String, Object> params,
HttpEntity body,
Map<String, Object> options,
Consumer<? super HttpResponse> action);

public static void post(
String uristr,
Map<String, String> headers,
Map<String, Object> params,
String body,
Map<String, Object> options,
Consumer<? super HttpResponse> action);
HTTP PUT
public static void put(String uristr,
Map<String, String> headers,
Map<String, Object> params,
HttpEntity body,
Map<String, Object> options,
Consumer<? super HttpResponse> action);

public static void put(
String uristr,
Map<String, String> headers,
Map<String, Object> params,
String body,
Map<String, Object> options,
Consumer<? super HttpResponse> action);
HTTP PATCH
public static void patch(
String uristr,
Map<String, String> headers,
Map<String, Object> params,
HttpEntity body,
Map<String, Object> options,
Consumer<? super HttpResponse> action);

public static void patch(
String uristr,
Map<String, String> headers,
Map<String, Object> params,
String body,
Map<String, Object> options,
Consumer<? super HttpResponse> action);
HTTP DELETE
public static void delete(
String uristr,
Map<String, String> headers,
Map<String, Object> params,
Map<String, Object> options,
Consumer<? super HttpResponse> action);

// When a request body is needed
public static void delete(
String uristr,
Map<String, String> headers,
Map<String, Object> params,
String body,
Map<String, Object> options,
Consumer<? super HttpResponse> action);
Utility Method
public static String responseToString(
HttpResponse response) throws ParseException, IOException;


public static String responseToString(
HttpResponse response,
String charset) throws ParseException, IOException;
* 
You must register external sites in the Remote Sites Whitelist setting before HTTP methods are called. This setting defines which external web sites can be accessed by Max applications. Format values in property-object format, with one key-value pair separated by a colon on each line, with the remote site URL as the value, for example:
site1:https://www.site1.com
site2:https://www.site2.com
Otherwise, calls to this API fail.
Example
import com.servicemax.core.utils.HttpRequestHelper
// this site must be registered in Remote Sites Whitelist setting beforehand
def uri = 'https://www.domain.com'
def result = ""
HttpRequestHelper.get(uri, null, null, [:], {response ->
result = HttpRequestHelper.responseToString(response, 'UTF-8')
});

result
For more information:
Was this helpful?