The http. get method in node. js is described as follows: node. jshttp. get
Method description:
Most requests do not contain GET requests of the Request body. Node. js provides a simpler method for requests.
The difference between this method and Http. request () is that this method is only requested in GET mode and will automatically call req. end () to end the request.
Syntax:
Copy codeThe Code is as follows:
Http. get (options, callback)
Because this method belongs to the http module, the http module (var http = require ("http") must be introduced before use "))
Receiving parameters:
Option indicates the domain name or IP address of the requested website (requested address)
The callback function passes a parameter res, that is, the response object, indicating the response to be made after receiving the request. For details about attributes of res, refer to "http. response attribute integration ".
Res is an http. ClientResponse instance.
Example:
Copy codeThe Code is as follows:
Http. get ("http://www.google.com/index.html", function (res ){
Console. log ("Got response:" + res. statusCode );
}). On ('error', function (e ){
Console. log ("Got error:" + e. message );
});
Source code:
Copy codeThe Code is as follows:
Exports. get = function (options, cb ){
Return globalAgent. get (options, cb );
};