-
Notifications
You must be signed in to change notification settings - Fork 6
http
- HTTP.exec
- HTTP.get
- HTTP.getErrorResponse
- HTTP.getResponse
- HTTP.http
- HTTP.login
- HTTP.response
- HTTP.responseBytes
- HTTP.responseCode
- HTTP.responseHeaders
- HTTP.responseStream
- HTTP.responseType
- HTTP.wsConnect
HTTP.exec(aUrl, aRequestType, aIn, aRequestMap, isBytes, aTimeout, returnStream) : Object
Builds a HTTP request for the aURL provided with aRequestType (e.g. "GET" or "POST") sending aIn body request (or "") and optionally sending aRequestMap headers and optionally specifying if the response isBytes and providing an optional custom HTTP aTimeout. If returnStream = true the response and return value will be in the form of a JavaStream.
HTTP.get(aUrl, aIn, aRequestMap, isBytes, aTimeout, returnStream)
Builds a HTTP request for the aURL with a POST sending aIn body request (or "") and optionally sending aRequestMap headers and optionally specifying if the response isBytes and providing an optional custom HTTP aTimeout. If returnStream = true, the response will be in the form of a JavaStream (please use the returnStream function).
HTTP.getErrorResponse() : Object
Returns the HTTP request error result string.
HTTP.getResponse() : Object
Returns the HTTP request result string or array of bytes.
HTTP.http(aURL, aRequestType, aIn, aRequestMap, isBytes, aTimeout, returnStream)
Builds a HTTP request for the aURL provided with aRequestType (e.g. "GET" or "POST") sending aIn body request (or "") and optionally sending aRequestMap headers and optionally specifying if the response isBytes and providing an optional custom HTTP aTimeout. If needed use java.lang.System.setProperty("sun.net.http.allowRestrictedHeaders", "true") to allow you to use restricted request headers. If returnStream = true, the response will be in the form of a JavaStream (please use the returnStream function).
HTTP.login(aUser, aPassword, forceBasic, urlPartial)
Tries to build a simple password authentication with the provided aUser and aPassword (encrypted or not). By default it tries to use the Java Password Authentication but it forceBasic = true it will force basic authentication to be use. It's advisable to use urlPartial to associate a login/password to a specific URL location.
HTTP.response() : String
Returns the HTTP request result as a string (if isBytes = false or default)
HTTP.responseBytes() : ArrayOfBytes
Returns the HTTP request result as an array of bytes (if isBytes = true)
HTTP.responseCode() : Number
Returns the HTTP request response code (e.g. 404, 500, ...)
HTTP.responseHeaders() : Map
Returns a Map with the response headers of the HTTP request.
HTTP.responseStream() : JavaStream
Returns a JavaStream if the option of returnStream = true in the previous instance function called.
HTTP.responseType() : String
Returns the HTTP request response content mime type.
HTTP.wsConnect(anURL, onConnect, onMsg, onError, onClose, aTimeout, supportSelfSigned) : WebSocketClient
Tries to establish a websocket connection (ws or wss) and returns a jetty WebSocketClient java object. As callbacks you should defined onConnect, onMsg, onError and onClose. The onConnect callback will provide, as argument, the created session that you should use to send data; the onMsg callback will provide, as arguments, aType (either "text" or "bytes"), aPayload (string or array of bytes) and an offset and length (in case type is "bytes"); the onError callback will provide the cause; the onClose callback will provide aStatusCode and aReason. You can optionally provide aTimeout (number) and indicate if self signed SSL certificates should be accepted (supportSelfSigned = true). Example:
plugin("HTTP");
var session; var output = "";
var client = (new HTTP()).wsConnect("ws://echo.websocket.org",
function(aSession) { log("Connected"); session = aSession; },
function(aType, aPayload, aOffset, aLength) { if (aType == "text") output += aPayload; },
function(aCause) { logErr(aCause); },
function(aStatusCode, aReason) { log("Closed (" + aReason + ")"); }
);
session.getRemote().sendString("Hello World!");
while(output.length < 1) { sleep(100); };
client.stop();
print(output);
NOTE: this functionality is only available if used with JVM >= 1.8