富贵资源网 Design By www.hznty.com

1、自己写

const http = require('http');
 
http.createServer(function(req,res){
  var get = {};
  if(req.url.indexOf('"htmlcode">
const http = require('http');
const querystring = require('querystring');
http.createServer(function(req,res){
  var get = {};
  if(req.url.indexOf('"htmlcode">
const http = require('http');
const urlli = require('url');
http.createServer(function(req,res){
  var obj = urlli.parse(req.url,true); //true解析,如果没有true,默认不解析
  var url = obj.pathname;
  var get = obj.query;
  console.log(url,get);
  res.write('aaa');
  res.end();
}).listen(8080);

提交表单的HTML代码

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Document</title>
</head>
<body>
  <form action="http://localhost:8080/aaa" method="get">
    用户:<input type="text" name="user" value=''><br>
    密码:<input type="password" name="pass" value=''><br>
    <input type="submit" value="提交">
  </form>
</body>
</html>

个人练习如下:

const http = require("http");
const queryString = require("querystring");
const urlNode = require('url');

http.createServer((req,res)=>{
  console.log(req.url);  // /aaa"([^", "gi");
    // var regSingle = new RegExp("([^", "i");
    // var arrAll = query.match(regAll);   //["user=123", "pass=456"]
    // arrAll.map(function(v,k,arr){
    //   var resultArr = v.match(regSingle);
    //   get[resultArr[1]] = resultArr[2];
    // })
    //方法三:引入querystring模块
    // const arr = req.url.split('"htmlcode">
app.get('/article',(req,res)=>{
  console.log(req.query)
  
})

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。

富贵资源网 Design By www.hznty.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
富贵资源网 Design By www.hznty.com