如何做优惠券网站,洛阳专业做网站多少钱,深圳建设交易网站,成都市互联网协会网页设计引入 URL 模块 要使用 URL 模块#xff0c;首先需要在代码中引入它。可以使用以下代码将 URL 模块导入到你的脚本中#xff1a;
const url require(url);实例代码
const urlrequire(url);
var apihttp://www.baidu.com?nameshixiaobinage20;
console.log(url.parse(…引入 URL 模块 要使用 URL 模块首先需要在代码中引入它。可以使用以下代码将 URL 模块导入到你的脚本中
const url require(url);实例代码
const urlrequire(url);
var apihttp://www.baidu.com?nameshixiaobinage20;
console.log(url.parse(api));
console.log(url.parse(api,true));var getValueurl.parse(api,true).query;console.log(getValue);//两种方法都能完成显示
console.log(姓名${getValue.name}--年龄${getValue.age}); //引号是TAB上面的‘不是普通的引号
console.log(姓名getValue.name--年龄getValue.age);http://127.0.0.1:3000/?nameshixiaobinage20 想获取url传过来的name和age
//引入http模块
const httprequire(http);
//引入url模块
const urlrequire(url);//http.createServer((req,res){
http.createServer(function (req,res) {//req 获取客户端传过来的信息//res 给浏览器响应信息//http://127.0.0.1:3000/?nameshixiaobinage20 想获取url传过来的name和age//设置响应头//状态码是200文件类型是html,字符集是utf-8res.writeHead(200,{Content-type:text/html;charsetutf-8}); //解决乱码res.write(headmeta charsetUTF-8/head); //如果没有这一行下面的 你好 是乱码 //解决乱码//console.log(req);//获取好多信息console.log(req.url);//获取urlif(req.url!/favicon.ico){var userinfourl.parse(req.url,true).query;console.log(姓名${userinfo.name}--年龄${userinfo.age});}res.end();//结束响应如果没有这一行浏览器左上角的图标一直在转圈
}).listen(3000); //端口建议3000以上防止冲突