const http=require('http');
//创建服务对象
//request是对浏览器请求报文的封装对象
//reponse是对服务器返回报文的封装对象
const server=http.createServer((request,response)=>{
//实例化URL对象
let url=new URL(request.url,'http://127.0.0.1:9000')
//输出路径
console.log(url.pathname);
//输出查询字符串
console.log(url.searchParams.get('keyword'));
response.end('url new')
})
//监听端口,启动服务
server.listen(9000,()=>{
console.log('服务已经启动...');
})
709_http模块_提取http报文的URL路径和查询字符串new
- 本文链接: http://lzkpersonal.com.cn/2023/07/09/709-http模块-提取http报文的URL路径和查询字符串new/
- 版权声明: 本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!