Method description:
Since most requests are GET requests that do not contain the request body. Node.js provides a simpler way to request.
The difference between this method and Http.request() is that the method only requests in GET mode and will automatically call req.end() to end the request.
grammar:
The code copy is as follows:
http.get(options, callback)
Since this method belongs to the http module, the http module needs to be introduced before use (var http= require("http") )
Receive parameters:
option means the domain name or IP address of the requested website (the requested address)
The callback callback function passes a parameter res, that is, the response object, indicating the response to be made after receiving the request. If you want to know what properties res have, you can check "http.response attribute integration".
res is an instance of http.ClientResponse.
example:
The code copy 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 copy is as follows:
exports.get = function(options, cb) {
return globalAgent.get(options, cb);
};