The http. get method in node. js is described as follows: node. jshttp. get

Source: Internet
Author: User

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 );
};

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.