0%

709_http模块_提取http报文的URL路径和查询字符串new

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('服务已经启动...');
})