Nodejs HTTP Network Module

Source: Internet
Author: User

Basic introduction

One of the most important aspects of NODEJS is the ability to implement HTTP and HTTPS servers and services very quickly. HTTP services are fairly low-level, you may want to use different modules, such as Express, to implement the complete Web server, the HTTP module does not provide processing routes, cookies, caches and other calls. Our main use of HTTP modules is where the backend Web services are implemented for application use.

Code section

Main API:

Http://nodejs.cn/api/http.html

Example:

get/** * HTTP GET request * HTTP://192.168.31.162:9001?NAME=001&PWD=AAAAAA */function Creategetserver () {http.        Createserver (function (req, res) {Res.writehead ($, {' Content-type ': ' Text/plain '});        Parse URL parameter console.log (req.url);        var params = Url.parse (Req.url, true). Query;        Res.write ("URL:" + req.url + "\ n");        Res.write ("Name:" + params.name + "\ n");        Res.write ("PWD:" + params.pwd);    Res.end (); }). Listen (9001);} post/** * HTTP POST request * HTTP://192.168.31.162:9002?NAME=001&PWD=AAAAAA * psot:{"AAA": "001"} */function        Createpostserver () {Http.createserver (function (req, res) {var params = Url.parse (Req.url, true). Query;        var body = "";            Req.on (' Data ', function (chunk) {body + = chunk;        Console.log (body);        });            Req.on (' End ', function () {//parse parameter//BODY = Querystring.parse (body); Setting the response header information and encoding Res.writeheaD ($, {' Content-type ': ' Text/html; Charset=utf8 '});            Res.write (body);        Res.end ();    }); }). Listen (9002);}

 

Reference:

Http://nodejs.cn/api/http.html

node. JS Get/post Request

node. JS Web Module

Nodejs HTTP Service

Node/lib/_http_server.js

Node.js--http Source Code Interpretation

An analysis of Nodejs HTTP module

nodejs--creating the simplest HTTP server

 

Nodejs HTTP Network Module

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.