Node. js processes post requests and node. jspost requests

Source: Internet
Author: User

Node. js processes post requests and node. jspost requests

1. html

 

2. app. js

Var http = require ('http') var qs = require ('querystring')/*** routing control function * @ param path */function rotuteHandle (request) {if (request. url = '/login' & request. method. toLowerCase () = 'post') {console. log ('Post request for login ') return 'Post method'} return 'get method'}/*** Server returns * @ param request * @ param response */function onRequest (request, response) {request. setEncoding ('utf-8') response. writeHead (200, {'content-type': 'text/plain '}) if (request. url = '/login' & request. method. toLowerCase () = 'post') {var postData = "" request. addListener ('data', function (data) {console. log ('get the post request parameters .. ') postData + = data}) request. addListener ('end', function () {console. log ('Post parameter retrieved successfully') console. log (postData) var content = qs. parse (postData ). text response. write (content) response. end ()} else {response. write ('other method') response. end ()} var server = http. createServer (onRequest) server. listen (3000) console. log ('server is Listening... ')

  

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.