Node.js_Get和Post

/**
 * Created by cxm on 2016/1/11.
 */

var http = require("http");
var url = require("url");
var util = require("util");
var querystring = require("querystring");

// Get
//http.createServer(function(req, res){
//    res.writeHead(200, {"Content-Type":"text/plain"});
//    res.end(util.inspect(url.parse(req.url, true)));
//}).listen(3000);

// Post
http.createServer(function(req, res){
    var post = "";
    req.on("data", function(chunk){
        post += chunk;
    });
    req.on("end", function(){
        console.log(post);
        post = querystring.parse(post);
        res.end(util.inspect(post));
    });
}).listen(3000);

發佈了260 篇原創文章 · 獲贊 7 · 訪問量 22萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章