This article mainly introduces node. http. get method instructions. This article introduces http. get method description, syntax, receive parameters, use instances, and implement Source Code. For more information, see
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:
The 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:
The 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:
The Code is as follows:
Exports. get = function (options, cb ){
Return globalAgent. get (options, cb );
};