美文网首页
POST数据请求

POST数据请求

作者: 王伯卿 | 来源:发表于2017-12-30 19:58 被阅读0次
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
</head>
<body>
  <form action="http://localhost:3000/user" method="post">
    username <input type="text" name="user" value=""><br>
    password <input type="password" name="password" value=""><br>
    <input type="submit" value="send">
  </form>
</body>
</html>
const http = require("http");

//GET数据的内容存在req.url中
//POST数据在内容部分,我们form表单提交的内容,就是POST数据
var server = http.createServer(function(req , res){
  //先声明一个空的字符串用来接收POST数据
  //不过这样不是好方法,因为这样没办法处理图片音频,暂时先这样
  var str = "";
  //data事件,用于接收POST数据,每一段POST数据过来的时候,都会发生一次
  req.on("data" , function(data){
    str += data;
  });
  //如果没有data数据后,end事件就会被触发
  req.on("end" , function(){
    console.log(str);
  });
}).listen(3000 , function(err){
  if(!err){
    console.log("server is listening 3000 port");
  }else{
    console.log(err);
  }
});

提交form表单后,后台将会打印出

user=abc&password=123

而这个就可以用querystring模块来处理了。

相关文章

  • curl相关操作

    GET请求 POST请求 POST请求,提交json格式数据 curl 的使用

  • POST请求

    POST请求通常向服务器发送应该被保存的数据。POST把数据作为请求的主体提交,POST请求应该主体包含非常多数据...

  • gf框架 ghttp使用

    案例中包含以下内容 get请求 get请求携带参数 post请求携带参数 post请求发送xml数据 post请求...

  • Ruby unirest发送post请求

    发送Post json格式数据请求 发送post form-data请求

  • Node.js学习第二天笔记

    1 发送请求的方式 1.1 post请求 post请求的数据在请求体中,不在地址栏中,可以传输大数据请求的数据为字...

  • GET和POST

    GET和POST请求的区别 GET请求 POST请求 提交 GET提交,请求的数据会附在URL之后(就是把数据放置...

  • IOS GET&POST请求

    GET请求 POST请求传递json数据

  • POST请求发出与解析-Python

    服务端接收json数据,返回json数据 POST请求发出端Python代码: # 发出POST请求 url ='...

  • 六、post请求

    POST请求相比较GET请求,POST请求比较复杂。因为 Node.js认为,使用POST请求时,数据量会比较多。...

  • 六:node——post请求

    post请求的数据比get大的多,所以post是分段发送请求的post方式接收数据用 res.on举个栗子: 结果...

网友评论

      本文标题:POST数据请求

      本文链接:https://www.haomeiwen.com/subject/bxengxtx.html