Home >Web Front-end >JS Tutorial >Instructions for using the http.request method in node.js_node.js
Method description:
The function room of the function acts as a client to initiate a request to the HTTP server.
Grammar:
Since this method belongs to the http module, the http module needs to be introduced before use (var http= require("http") )
Receive parameters:
option array object, containing the following parameters:
Host: Represents the domain name or IP address (requested address) of the requested website. Defaults to 'localhost'.
Hostname: Server name, hostname is the preferred value.
port: The port of the requested website, the default is 80.
localAddress: Local location to establish network connection
socketPath: Unix Domain Socket (Domain socket path)
method: HTTP request method, the default is ‘GET’.
path: The requested path relative to the root, the default is '/'. QueryString should be included in it. For example: /index.html?page=12
headers: Request header object.
auth: Basic authentication (Basic authentication), this value will be calculated as the Authorization part of the request header.
callback: callback, passing a parameter, which is an instance of http.ClientResponse. http.request returns an instance of http.ClientRequest.
Example: