相关疑难解决方法(0)

使用Nodejs HTTP Server的自定义HTTP方法

目前正在通过HTTP编写同步机制,我开始在NodeJS上构建我的服务器,这看起来是一个很好的解决方案.

好的,我可以让GET和HEAD方法正常工作.但是一旦我尝试使用非标准方法,例如"SYNC".这是代码:

var http = require("http");
var server = http.createServer(function (req, res) {
    res.writeHead(200);
    res.end(req.method);
});
server.listen(8080);
Run Code Online (Sandbox Code Playgroud)

看起来没问题......让我们telnet这个,发出一个GET,然后发出一个SYNC请求

mylaptop:~ aob$ telnet localhost 8080
Trying ::1...
telnet: connect to address ::1: Connection refused
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
GET / HTTP/1.1

HTTP/1.1 200 OK
Connection: keep-alive
Transfer-Encoding: chunked

3
GET
0

SYNC / HTTP/1.1
Connection closed by foreign host.
Run Code Online (Sandbox Code Playgroud)

关于如何让SYNC工作的任何想法?

networking http node.js

18
推荐指数
2
解决办法
2977
查看次数

disable http method in express js

im doing nessus testing on my express app and here what i get

基于每种方法的测试:

  • HTTP methods ACL CHECKOUT COPY DELETE GET HEAD LOCK MERGE MKACTIVITY MKCOL MOVE NOTIFY OPTIONS PATCH POST PROPFIND PROPPATCH PUT REPORT SEARCH SUBSCRIBE TRACE UNLOCK UNSUBSCRIBE are allowed on :

    //登录/样式

我做了一些搜索,实际上最终来到了这里。 disable HTTP methods, TRACK TRACE etc

解决方案

const allowedMethods = ['GET','HEAD','POST'];

function onrequest(req, res) {
  if (!allowedMethods.includes(req.method))
    return res.end(405, 'Method Not Allowed');
  // ...
}
Run Code Online (Sandbox Code Playgroud)

however i do not understand how to use the …

http http-method node.js

2
推荐指数
1
解决办法
4508
查看次数

标签 统计

http ×2

node.js ×2

http-method ×1

networking ×1