数据提交的两种方式:GET, POST
GET方式数据放在url里进行提交,容量有限,有缓存
//GET表单.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"><br>
密码:<input type="password" name="pwd"><br>
<input type="submit" value="submit">
</form>
</body>
</html>
Node服务器获取用户名与密码
//get_server.js
const http=require('http');
const url=require('url');
createServer((req,res)=>{
let query=url.parse(req.url, true);
console.log('user:'+query.user+',password:'+query.pwd)
}).listen(8080)
url.parse解析的是整个url
url.parse(req.url, true)打印出来的内容:
Url {
protocol: null,
slashes: null,
auth: null,
host: null,
port: null,
hostname: null,
hash: null,
search: '?user=123&pwd=2345',
query: { user: '123', pwd: '2345' },
pathn