HttpClient
Overview
A wrapper for Apache HttpClient
for executing requests like GET, POST, PUT, and more, with support for cookies, proxies, and timeouts.
Features
The client facilitates various HTTP requests (e.g., GET, POST, DELETE) and supports configuration options like cookies, proxy servers, and timeouts. It enables both synchronous and asynchronous communication, offering flexibility for different use cases.
For configuration details, see the Http client configuration section.
Methods Summarized
void
releases all resources that this client has, should be called after usage.
Creates a new delete request (a request to delete a resource on server).
Creates a new get request (retrieves whatever information is stored on specified url).
Creates a new head request (similar to get request, must not contain body content).
Creates a new options request (a request for information about communication options).
Creates a new patch request (used for granular updates).
Create a new post request ( Origin server should accept/process the submitted data.
Creates a new put request (similar to post request, contains information to be submitted).
Creates a new trace request (debug request, server will just echo back).
Execute multiple requests asynchronously.
Execute multiple requests asynchronously, it assumes that all request are to the same server (it gives the same username, password to all requests).
Execute multiple requests asynchronously, it assumes that all request are to the same server (it gives the same username, password, workstation and domain to all requests).
Get a cookie by name.
Get all cookies from this client.
void
Set proxy credentials.
void
Set proxy server.
Add cookie to the this client.
Add cookie to the this client.
Add cookie to the this client.
Add cookie to the this client.
Add cookie to the this client.
void
Sets a timeout in milliseconds for retrieving of data (when 0 there is no timeout).
Methods Detailed
close()
releases all resources that this client has, should be called after usage.
Returns: void
createDeleteRequest(url)
Creates a new delete request (a request to delete a resource on server).
Parameters
String url ;
Returns: DeleteRequest a DeleteRequest object for creating a DELETE request to the specified URL.
Sample
createGetRequest(url)
Creates a new get request (retrieves whatever information is stored on specified url). If this url is a https ssl encrypted url which certificates are not in the java certificate store. (Like a self signed certificate or a none existing root certificate) Then for a smart client a dialog will be given, to give the user the ability to accept this certificate for the next time. For a Web or Headless client the system administrator does have to add that certificate (chain) to the java install on the server. See https://wiki.servoy.com/display/tutorials/Import+a+%28Root%29+certificate+in+the+java+cacerts+file
Parameters
String url ;
Returns: GetRequest a GetRequest object for creating a GET request to the specified URL.
Sample
createHeadRequest(url)
Creates a new head request (similar to get request, must not contain body content).
Parameters
String url ;
Returns: HeadRequest a HeadRequest object for creating a HEAD request to the specified URL.
Sample
createOptionsRequest(url)
Creates a new options request (a request for information about communication options).
Parameters
String url ;
Returns: OptionsRequest an OptionsRequest object for creating an OPTIONS request to the specified URL.
Sample
createPatchRequest(url)
Creates a new patch request (used for granular updates).
Parameters
String url ;
Returns: PatchRequest a PatchRequest object for creating a PATCH request to the specified URL.
Sample
createPostRequest(url)
Create a new post request ( Origin server should accept/process the submitted data.) If this url is a https ssl encrypted url which certificates are not in the java certificate store. (Like a self signed certificate or a none existing root certificate) Then for a smart client a dialog will be given, to give the user the ability to accept this certificate for the next time. For a Web or Headless client the system administrator does have to add that certificate (chain) to the java install on the server. See https://wiki.servoy.com/display/tutorials/Import+a+%28Root%29+certificate+in+the+java+cacerts+file
Parameters
String url ;
Returns: PostRequest a PostRequest object for creating a POST request to the specified URL.
Sample
createPutRequest(url)
Creates a new put request (similar to post request, contains information to be submitted).
Parameters
String url ;
Returns: PutRequest a PutRequest object for creating a PUT request to the specified URL.
Sample
createTraceRequest(url)
Creates a new trace request (debug request, server will just echo back).
Parameters
String url ;
Returns: TraceRequest a TraceRequest object for creating a TRACE request to the specified URL.
Sample
execute(requests)
Execute multiple requests asynchronously. A Promise is returned that resolves with an array of Response objects when all requests are complete in the same order as the Request objects. Because some request can fail and others can just work, this promise will always just resolve (not reject) with response object having the message of the error or the actual normal response.
Parameters
Array requests ;
Returns: Promise The promise object that resolves with an array of Response objects when all requests are complete in the same order as the Request objects.
Sample
executeRequest(requests, username, password)
Execute multiple requests asynchronously, it assumes that all request are to the same server (it gives the same username, password to all requests).
A Promise is returned that resolves with an array of Response objects when all requests are complete in the same order as the Request objects. Because some request can fail and others can just work, this promise will always just resolve (not reject) with response object having the message of the error or the actual normal response.
Parameters
Returns: Promise The promise object that resolves with an array of Response objects when all requests are complete in the same order as the Request objects.
Sample
executeRequest(requests, username, password, workstation, domain)
Execute multiple requests asynchronously, it assumes that all request are to the same server (it gives the same username, password, workstation and domain to all requests).
A Promise is returned that resolves with an array of Response objects when all requests are complete in the same order as the Request objects. Because some request can fail and others can just work, this promise will always just resolve (not reject) with response object having the message of the error or the actual normal response.
BaseRequest[] request
Parameters
Array requests ;
String username the user name
String password the password
String workstation The workstation the authentication request is originating from.
String domain The domain to authenticate within.
Returns: Promise The promise object that resolves with an array of Response objects when all requests are complete in the same order as the Request objects.
getCookie(cookieName)
Get a cookie by name.
Parameters
String cookieName ;
Returns: Cookie the cookie with the specified name, or null if it does not exist.
Sample
getCookies()
Get all cookies from this client.
Returns: Array an array of all cookies currently stored in the client.
Sample
setClientProxyCredentials(userName, password)
Set proxy credentials.
Parameters
Returns: void
Sample
setClientProxyServer(hostname, port)
Set proxy server.
Parameters
String hostname - proxy host // null value will clear proxyHost settings;
Number port - proxy port //null value will clear proxyHost settings;
Returns: void
Sample
setCookie(cookieName, cookieValue)
Add cookie to the this client.
Parameters
Returns: Boolean true if the cookie was successfully set; otherwise, false.
Sample
setCookie(cookieName, cookieValue, domain)
Add cookie to the this client.
Parameters
String cookieName the name of the cookie
String cookieValue the value of the cookie
String domain the domain
Returns: Boolean true if the cookie was successfully set; otherwise, false.
Sample
setCookie(cookieName, cookieValue, domain, path)
Add cookie to the this client.
Parameters
String cookieName the name of the cookie
String cookieValue the value of the cookie
String domain the domain
String path the path
Returns: Boolean true if the cookie was successfully set; otherwise, false.
Sample
setCookie(cookieName, cookieValue, domain, path, maxAge)
Add cookie to the this client.
Parameters
String cookieName the name of the cookie
String cookieValue the value of the cookie
String domain the domain
String path the path
Number maxAge maximum age of cookie
Returns: Boolean true if the cookie was successfully set; otherwise, false.
Sample
setCookie(cookieName, cookieValue, domain, path, maxAge, secure)
Add cookie to the this client.
Parameters
String cookieName the name of the cookie
String cookieValue the value of the cookie
String domain the domain
String path the path
Number maxAge maximum age of cookie
Boolean secure true if it is a secure cookie, false otherwise
Returns: Boolean true if the cookie was successfully set; otherwise, false.
Sample
setTimeout(msTimeout)
Sets a timeout in milliseconds for retrieving of data (when 0 there is no timeout).
Parameters
Object msTimeout ;
Returns: void
Sample
Last updated
Was this helpful?