- 主要是获取数据
- 数据放在url里进行传输
- 容量小 <32k
使用:
在先把get-test.html在浏览器上运行起来
get-test.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<form action="http://localhost:8888/aaaa">
用户名:<input type="text" name="username"><br>
密码:<input type="password" name="password"><br>
<input type="submit" value="提交">
</form>
</body>
</html>
get.js
let http = require('http')
let url = require('url')
http.createServer((req, res) => {
console.log(req.url); // /aaaa?username=admin&password=123
console.log(url.parse(req.url, true));
// 获取url和传参,url.parse() 为true 表示 解析更简洁
let { pathname, query } = url.parse(req.url, true)
// console.log(pathname, query);
}).listen(8888)