zoukankan      html  css  js  c++  java
  • node.js的POST

    post请求的接收

    相比较GET请求,POST请求比较复杂,因为nodejs认为使用post请求时数据量会比较多,为了追求极致的效率,nodeJS 将数据拆分称为了很多小的数据块(chunk),然后通过特定的事件,讲这些小数据块有序传递给回调函数。
    post请求使用body-parser获取提交的数据。
    
    html:   <form action="http://127.0.0.1/dopost" method="post">
    姓名: <input type="text" name="username">
    性别: <input type="radio" name="sex">男<input type="radio" name="sex">女
    
    post.js:
    var http = require('http')
    var querystring = require('querystring)
    var server = http.createServer(function(req,res){
    
        if(req.url == '/dopost' && req.method.toLowerCase == 'post'){
    
            var allData = '';
            req.addListener('data',function(chunk){
        
                allData += chunk
    
            })
    
            req.addListener('end',function(){
                console.log(allData.toString);
                var param = querystring.parse(allData); //可以直接解码
                res.end(param.name)
            })
    
        }
    
    })
  • 相关阅读:
    Docker build Dockerfile 构建镜像
    Docker 容器启动 查看容器状态
    Docker 获取镜像
    Docker 容器状态查看
    windows 检测进程pid
    bzoj 1083 最小生成树
    bzoj 2039 最小割模型
    bzoj 2749 杂题
    bzoj 2748 DP
    bzoj 3190 维护栈
  • 原文地址:https://www.cnblogs.com/rainbow8590/p/7123398.html
Copyright © 2011-2022 走看看