
Product
Secure Your AI-Generated Code with Socket MCP
Socket MCP brings real-time security checks to AI-generated code, helping developers catch risky dependencies before they enter the codebase.
xmlhttprequest-ssl
Advanced tools
The xmlhttprequest-ssl package is a Node.js module that provides an implementation of the XMLHttpRequest object, which is primarily used in web browsers for making HTTP requests. This package is designed to work with SSL (Secure Sockets Layer) for secure data transmission and is particularly useful for server-side applications that need to make HTTP requests in a way that's similar to client-side JavaScript code.
Making GET Requests
This feature allows you to make GET requests to retrieve data from a specified URL. The code sample demonstrates how to initiate a GET request, handle the response, and print the result or error.
const XMLHttpRequest = require('xmlhttprequest-ssl').XMLHttpRequest;
const xhr = new XMLHttpRequest();
xhr.open('GET', 'https://api.example.com/data', true);
xhr.onload = function () {
if (xhr.status >= 200 && xhr.status < 300) {
console.log('Response:', xhr.responseText);
} else {
console.error('Request failed');
}
};
xhr.send();
Sending POST Requests
This feature enables sending POST requests to submit data to a server. The code sample shows how to set up a POST request, including setting the request header and sending data in JSON format.
const XMLHttpRequest = require('xmlhttprequest-ssl').XMLHttpRequest;
const xhr = new XMLHttpRequest();
xhr.open('POST', 'https://api.example.com/submit', true);
xhr.setRequestHeader('Content-Type', 'application/json;charset=UTF-8');
xhr.onload = function () {
if (xhr.status >= 200 && xhr.status < 300) {
console.log('Success:', xhr.responseText);
} else {
console.error('Request failed');
}
};
xhr.send(JSON.stringify({ key: 'value' }));
Axios is a popular HTTP client for the browser and Node.js. It provides a promise-based API and is capable of making XMLHttpRequests from the browser and http requests from Node.js. Compared to xmlhttprequest-ssl, Axios offers a more modern API, automatic JSON data transformation, and request and response interception.
node-fetch is a lightweight module that brings the Fetch API to Node.js. It aims to provide a consistent API with the browser's Fetch API, making it easy for developers to write isomorphic code that works on both the client and server. Unlike xmlhttprequest-ssl, node-fetch uses Promises, which can simplify asynchronous code.
Got is a human-friendly and powerful HTTP request library for Node.js. It supports redirections, retries, streams, and more. Got is designed to be a simpler and more usable alternative to Node's native http module, and it offers more advanced features compared to xmlhttprequest-ssl, such as built-in JSON parsing and improved error handling.
Fork of node-XMLHttpRequest by driverdan. Forked and published to npm because a pull request is not being created and merged. Changes made by rase- are needed for engine.io-client.
Here's how to include the module in your project and use as the browser-based XHR object.
var XMLHttpRequest = require("xmlhttprequest-ssl").XMLHttpRequest;
var xhr = new XMLHttpRequest();
Note: use the lowercase string "xmlhttprequest-ssl" in your require(). On case-sensitive systems (eg Linux) using uppercase letters won't work.
Non-standard options for this module are passed through the XMLHttpRequest
constructor. Here is the list of all options:
Option | Default value | Description |
---|---|---|
ca | undefined | Control https: requests, you can find their functionality in the Nodejs Documentation |
cert | ||
ciphers | ||
key | ||
passhphrase | ||
pfx | ||
rejectUnauthorized | true | |
agent | undefined | Allows to specify a Nodejs Agent instance, allowing connection reuse |
autoUnref | false | Set to any truthy value to prevent a process from not exiting naturally because a request socket from this module is still open |
maxRedirects | 20 | Allows control over the maximum number of redirects that are followed |
allowFileSystemResources | true | Allows control access to the local filesystem through the file: protocol |
origin | undefined | Set a base URL for the requests called using this instance. The resulting request URL will be constructed as follows: new URL(url, origin) |
syncPolicy | "warn" | Control feature behavior of the synchronous feature:
|
disableHeaderCheck | false | Disable the check against forbidden headers to be added to a XHR request |
xmlParser | none | Specify a parser (non-async) to parse document from text when xhr.responseType is either "document" or in text format. If the parser is invalid or omitted, xhr.responseXML will be null |
textDecoder | TextDecoder or buf.toString(enc) depending on Node version | Specify a text decoder (non-async), accepting a buffer buf and encoding enc to decode to desired encoding.Note that TextDecoder at version 12 does not support a wide range of encodings than later node version does |
XMLHttpRequest
object created using this library exposes xhr.getRequestHeader(header_name)
method to retrieve any header content by name in the request headers list. This feature is deprecated and will be removed in future releases.
Version 2.0.0 introduces a potentially breaking change concerning local file system requests.
If these requests fail this library now returns the errno
(or -1) as the response status code instead of
returning status code 0.
Prior to 1.4.0 version numbers were arbitrary. From 1.4.0 on they conform to the standard major.minor.bugfix. 1.x shouldn't necessarily be considered stable just because it's above 0.x.
Since the XMLHttpRequest API is stable this library's API is stable as well. Major version numbers indicate significant core code changes. Minor versions indicate minor core code changes or better conformity to the W3C spec.
MIT license. See LICENSE for full details.
For a list of open issues or to report your own visit the github issues page.
FAQs
XMLHttpRequest for Node
The npm package xmlhttprequest-ssl receives a total of 3,232,886 weekly downloads. As such, xmlhttprequest-ssl popularity was classified as popular.
We found that xmlhttprequest-ssl demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket MCP brings real-time security checks to AI-generated code, helping developers catch risky dependencies before they enter the codebase.
Security News
As vulnerability data bottlenecks grow, the federal government is formally investigating NIST’s handling of the National Vulnerability Database.
Research
Security News
Socket’s Threat Research Team has uncovered 60 npm packages using post-install scripts to silently exfiltrate hostnames, IP addresses, DNS servers, and user directories to a Discord-controlled endpoint.