-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparameter.js
More file actions
36 lines (28 loc) · 908 Bytes
/
parameter.js
File metadata and controls
36 lines (28 loc) · 908 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/**
* @author : cpucode
* @date : 2021/3/22
* @time : 10:58
* @github : https://github.com/CPU-Code
* @csdn : https://blog.csdn.net/qq_44226094
*/
//引入http模块
var http = require("http");
var url = require("url");
//创建服务,监听8888端口
http.createServer(function (request, response) {
//发送http头部
//http响应状态200
//http响应内容类型为text/plain
response.writeHead(200, {"Content-Type":"text/plain"});
//解析参数
//参数1:请求地址;
//参数2:true时query解析参数为一个对象,默认false
var params = url.parse(request.url, true).query;
//将所有请求参数输出
for (var key in params) {
response.write( key + " = " + params[key]);
response.write("\n");
}
response.end("");
}).listen(8888);
console.log("Server running at http://127.0.0.1:8888?id=100&name=cpucode");