Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/37.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 如何检查客户机´;s请求是http请求吗?节点js_Node.js - Fatal编程技术网

Node.js 如何检查客户机´;s请求是http请求吗?节点js

Node.js 如何检查客户机´;s请求是http请求吗?节点js,node.js,Node.js,我有一个TCP服务器,它接收来自客户端的请求。我想确定这是一个http请求 这是我的服务器: var server = net.createServer(function (socket) { socket.setEncoding("utf8"); console.log("Connections stated by:" + socket.address().address); socket.write("hi tcp\r\n"); socket.on("data

我有一个TCP服务器,它接收来自客户端的请求。我想确定这是一个http请求

这是我的服务器:

var server = net.createServer(function (socket) {
    socket.setEncoding("utf8");
    console.log("Connections stated by:" + socket.address().address);
    socket.write("hi tcp\r\n");
    socket.on("data",function(chunk) {
        console.log("received the following data: " + chunk);
        var request = requestParser.parseRequest(chunk);
    });         
});
在requestParser中,我解析chunk并使用
querystring
获取方法和请求,但是我如何知道这是一个http请求呢?我必须解析请求的第三个参数来检查它是否等于HTTP/1.1?有没有一个功能可以为我做到这一点

谢谢你

你为什么不使用