简体   繁体   中英

What is the difference between request and http modules in node.js?

My task is a very simple one, send an http/https request to a server, get back the HTML,JSON or XML and process the data.

I understand that there are 2 modules that can do the module part. nodejs.org/api/http.html and https://www.npmjs.com/package/request

I guess request is more advanced. Other than that is there any difference between the 2 which makes one more suitable or less suitable for the task I said?

The http package contains support for the raw HTTP protocol. While it can do everything, often it's a bit clumsy to use.

The request module uses the http module and adds a lot of sugar to make it easier to digest: A lot of common cases can be handled with just a tiny bit of code, it supports piping request data, forwarding requests to a different server, etc.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM