http

(plugins.http)

Overview

The HttpClient plugin allows the creation of HttpClient objects to perform HTTP requests, functioning like a web browser without a user interface, with session binding capabilities. It supports operations such as creating and configuring clients, fetching media data, and retrieving page HTML. The plugin provides several return types, including various HTTP request and response objects, cookies, configurations, and HTTP status codes.

HttpClient objects can be created for executing multiple requests in the same server session. Users must close these client objects after usage to free resources. Configurations for HttpClient instances can also be created, allowing customization of request settings. For fetching binary media data like images, the getMediaData(url) method is available, ensuring compatibility with HTTPS by requiring known certificates or enabling prompts for unknown ones. To fetch the entire HTML content of a page, the getPageData(url) method can be used, with similar considerations for HTTPS certificates.

Returned Types

PatchRequest,PostRequest,PutRequest,GetRequest,DeleteRequest,OptionsRequest,HeadRequest,TraceRequest,Cookie,Response,HttpClient,HttpClientConfig,HTTP_STATUS,JSFileUpload,

Methods Summarized

Type
Name
Summary

Create an http client (like a web browser with session binding) usable todo multiple request/posts in same server session .

Create an http client (like a web browser with session binding) usable todo multiple request/posts in same server session.

Get media (binary data) such as images in a variable.

Get all page html in a variable, if this url is an https url that uses certificates unknown to Java then you have to use the HttpClient so that smart client users will get the unknown certificate dialog that they then can accept or you must make sure that those server certificates are stored in the cacerts of the java vm that is used (this is required for a web or headless client)

Methods Detailed

createNewHttpClient()

Create an http client (like a web browser with session binding) usable todo multiple request/posts in same server session . WARNING: Make sure you call client.close() on it after you used this client object to clean up resources. Starting a HTTPClient is the same as starting an actual browser without UI!

Returns: HttpClient

Sample

var client = plugins.http.createNewHttpClient();

createNewHttpClient(config)

Create an http client (like a web browser with session binding) usable todo multiple request/posts in same server session.

WARNING: Make sure you call client.close() on it after you used this client object to clean up resources. Starting a HTTPClient is the same as starting an actual browser without UI!

Parameters

Returns: HttpClient

Sample

var client = plugins.http.createNewHttpClient(config);

createNewHttpClientConfig()

Create a http client config

Returns: HttpClientConfig

Sample

var config = plugins.http.createNewHttpClientConfig();

getMediaData(url)

Get media (binary data) such as images in a variable. It also supports gzip-ed content. If this url is an https url that uses certificates unknown to Java then you have to use the HttpClient so that smart client users will get the unknown certificate dialog that they then can accept or you must make sure that those server certificates are stored in the cacerts of the java vm that is used (this is required for a web or headless client)

Parameters

Returns: Array

Sample

var image_byte_array = plugins.http.getMediaData('http://www.cnn.com/cnn.gif');

getPageData(url)

Get all page html in a variable, if this url is an https url that uses certificates unknown to Java then you have to use the HttpClient so that smart client users will get the unknown certificate dialog that they then can accept or you must make sure that those server certificates are stored in the cacerts of the java vm that is used (this is required for a web or headless client)

Parameters

Returns: String

Sample

// get data using a default connection
var pageData = plugins.http.getPageData('http://www.cnn.com');

Last updated