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:
Property | Type | Required | Description |
---|---|---|---|
cVerb | string | Yes | HTTP method such as "GET", "POST", "PUT", "DELETE", etc. |
cURL | string | Yes | The URL to send the request to |
aHeaders | array | No | Array of header objects, each containing name and value properties |
oRequest | object | No | ReadStream object containing the request body data |
oHandler | object | No | Object containing a response callback function. See below. |
oAuthenticate | object | No | Not used by Revu |
oHandler
The oHandler parameter is an object literal containing a callback function that is called when the HTTP response is received.
Property | Description |
---|---|
response | Callback function executed when the HTTP response is received |
response
The response callback function receives the following parameters:
oStream
: ReadStream object containing the response bodycURL
: The URL that was requestedoException
: Error object witherror
andmsg
properties if an error occurred, null otherwiseaHeaders
: Array of response header objects, each containingname
andvalue
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);
}
}
});