HTTP Client

HTTP Client is used by scripting services to call external services via HTTP.

Version 3.x

Basic Usage

1
2
3
4
5
6
7
8
9
var httpClient = require('http/v3/client');
var response = require('http/v3/response');

var httpResponse = httpClient.get('http://services.odata.org/V4/Northwind/Northwind.svc/');

response.println(httpResponse.statusMessage);
response.println(httpResponse.text);
response.flush();
response.close();

Definition

Functions


Function Description Returns
get(url, options) Makes a HTTP GET request to a remote service at the URL by the HttpOptions and returns the result HttpResponse
post(url, options) Makes a HTTP POST request to a remote service at the URL by the HttpOptions and returns the result HttpResponse
put(url, options) Makes a HTTP PUT request to a remote service at the URL by the HttpOptions and returns the result HttpResponse
delete(url, options) Makes a HTTP DELETE request to a remote service at the URL by the HttpOptions and returns the result HttpResponse
head(url, options) Makes a HTTP HEAD request to a remote service at the URL by the HttpOptions and returns the result HttpResponse
trace(url, options) Makes a HTTP TRACE request to a remote service at the URL by the HttpOptions and returns the result HttpResponse

Objects


HttpResponse

Property Description Type
statusCode The Response status code int
statusMessage The Response status message string
data The Response data array of bytes
text The Response data as text string
binary Whether the Response data is binary in data or string in text boolean
protocol The HTTP version of the Response string
headers The Response headers array of HttpHeader

HttpHeader

Property Description Type
name The name of the header string
value The value of the header string

HttpParam

Property Description Type
name The name of the param string
value The value of the param string

HttpOptions

Property Description Type
data The body of the HTTP Request as binary array of bytes
text The body of the HTTP Request as text string
files The body of the HTTP Request as files (for POST) array of strings
params The body of the HTTP Request as form parameters array of HttpParam
binary Whether the body of the HTTP Request is binary boolean
characterEncoding The character encoding parameter. Default is UTF-8 string
contentType The content type parameter. Default is plain/text string
headers The Response headers array of HttpHeader
proxyHost The proxy host parameter string
proxyPort The proxy port parameter int
expectContinueEnabled The continue enabled parameter boolean
cookieSpec The cookieSpec parameter string
redirectsEnabled The redirects enabled parameter boolean
relativeRedirectsAllowed The relative redirects allowed parameter boolean
circularRedirectsAllowed The circular redirects allowed parameter boolean
maxRedirects The max redirects parameter int
authenticationEnabled The authentication enabled parameter boolean
targetPreferredAuthSchemes The target preferred authentication schemes parameter array of strings
proxyPreferredAuthSchemes The proxy preferred authentication schemes parameter array of strings
connectionRequestTimeout The connection request timeout parameter int
connectTimeout The connect timeout parameter int
socketTimeout The socket timeout parameter int
contentCompressionEnabled The content compression enabled parameter boolean
sslTrustAllEnabled The SSL trust all enabled parameter boolean

Compatibility

Rhino Nashorn V8
βœ… βœ… βœ…


Version 2.x

Basic Usage

1
2
3
4
5
6
7
8
9
10
11
12
/* globals $ */
/* eslint-env node, dirigible */

var httpClient = require('net/http/client');
var response = require('net/http/response');

var httpResponse = httpClient.get('http://services.odata.org/V4/Northwind/Northwind.svc/');

response.println(httpResponse.statusMessage);
response.println(httpResponse.data);
response.flush();
response.close();

Definition

Functions


Function Description Returns
get(url, options) Makes a HTTP GET request to a remote service at the URL by the HttpOptions and returns the result HttpResponse
post(url, options) Makes a HTTP POST request to a remote service at the URL by the HttpOptions and returns the result HttpResponse
put(url, options) Makes a HTTP PUT request to a remote service at the URL by the HttpOptions and returns the result HttpResponse
delete(url, options) Makes a HTTP DELETE request to a remote service at the URL by the HttpOptions and returns the result HttpResponse
request(options) Makes a HTTP request to a remote service and returns the result HttpResponse

Objects


HttpResponse

Function Description Returns
statusCode The Response status code int
statusMessage The Response status message string
data The Response data array of bytes
httpVersion The HTTP version of the Response string
headers The Response headers array of HttpHeader

HttpHeader

Function Description Returns
name The name of the header string
value The value of the header string

HttpOptions

Function Description Returns
host The host parameter string
port The port parameter int
method The method parameter - GET, POST, PUT, DELETE. Default GET string
body The body of the HTTP Request string
charset The charset parameter. Default string
headers The Response headers array of HttpHeader

Compatibility

Rhino Nashorn V8
βœ… βœ… ❌
Edit