当前位置 : 主页 > 网络编程 > JavaScript >

node.js url

来源:互联网 收集:自由互联 发布时间:2021-06-28
nd24h_5_1.js var http = require('http');var url = require('url');http.createServer(function (req, res) { // req.url包含请求url字符串 // url模块的parse()方法根据url字符串解析出一个url对象 var reqUrl = url.parse(req.ur
nd24h_5_1.js
var http = require('http');
var url = require('url');

http.createServer(function (req, res) {
    // req.url包含请求url字符串
    // url模块的parse()方法根据url字符串解析出一个url对象
    var reqUrl = url.parse(req.url);
    var text = "";
    text += "path: " + reqUrl.path + "\n";
    text += "pathname: " + reqUrl.pathname + "\n";
    text += "search: " + reqUrl.search + "\n";
    text += "query: " + reqUrl.query + "\n";
    text += "hash: " + reqUrl.hash + "\n";

    res.writeHead(200, {
        'Content-Type': 'text/plain'
    });
    res.end(text);
}).listen(3000, '127.0.0.1');
QQ五笔截图未命名.png
网友评论