Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Net.HTTP

Net.HTTP provides HTTP request functionality for making web requests from within PDF JavaScript. This object enables communication with web servers to send and receive data.

Net.HTTP requires elevated privileges to function. Scripts must be trusted or run in a privileged context.

methods

request

Secure
Yes

Performs an HTTP request to a specified URL with configurable options.

request(oRequest)

oRequest: Object containing the request configuration with the following properties:

PropertyTypeRequiredDescription
cVerbstringYesHTTP method such as "GET", "POST", "PUT", "DELETE", etc.
cURLstringYesThe URL to send the request to
aHeadersarrayNoArray of header objects, each containing name and value properties
oRequestobjectNoReadStream object containing the request body data
oHandlerobjectNoObject containing a response callback function. See below.
oAuthenticateobjectNoNot used by Revu

oHandler

The oHandler parameter is an object literal containing a callback function that is called when the HTTP response is received.

PropertyDescription
responseCallback function executed when the HTTP response is received

response

The response callback function receives the following parameters:

  • oStream: ReadStream object containing the response body
  • cURL: The URL that was requested
  • oException: Error object with error and msg properties if an error occurred, null otherwise
  • aHeaders: Array of response header objects, each containing name and value properties

example:

// Simple GET request
Net.HTTP.request({
    cVerb: "GET",
    cURL: "https://api.example.com/data",
    oHandler: {
        response: function(stream, url, exception) {
            if (exception) {
                console.println("Error: " + exception.msg);
            } else {
                var responseText = util.stringFromStream(stream, "utf-8");
                console.println("Response: " + responseText);
            }
        }
    }
});
// POST request with headers and body
var requestBody = util.streamFromString(JSON.stringify({
    name: "Example",
    value: 123
}), "utf-8");

Net.HTTP.request({
    cVerb: "POST",
    cURL: "https://api.example.com/submit",
    aHeaders: [
        { name: "Content-Type", value: "application/json" },
        { name: "Authorization", value: "Bearer token123" }
    ],
    oRequest: requestBody,
    oHandler: {
        response: function(stream, url, exception, headers) {
            if (exception) {
                console.println("Request failed: " + exception.msg);
                return;
            }
            
            // Process response headers
            if (headers) {
                headers.forEach(function(header) {
                    console.println(header.name + ": " + header.value);
                });
            }
            
            // Process response body
            var responseText = util.stringFromStream(stream, "utf-8");
            console.println("Server response: " + responseText);
        }
    }
});