我正在尝试访问 Node 中的 WebDAV 服务器的内容(服务器正常,我可以网络使用它)。我正在使用request模块:
path = url.join(this._options.rootUrl, path || "");
var data =
"<?xml version=\"1.0\" encoding=\"utf-8\" ?>" +
"<propfind xmlns=\"DAV:\">" +
"<propname/>" +
"</propfind>";
var headers = {
"Content-Type": "text/xml",
"Depth": depth || 1
};
var req = request({
url: path,
data: data,
headers: headers,
method: "PROPFIND",
json: false,
encoding: "utf8",
auth: {
user: this._options.user,
password: this._options.password
}
});
req.on("response", ...);
req.on("error", ...);
问题是我得到的是 HTTP 405 而不是结果。我尝试过捆绑 https 模块,结果相同。
Node.js 是否有可能无法调用像 PROPFIND 这样的自定义动词?
更新1:
这说明 Node 可以执行 PROFIND。所以我的问题是,你们如何使用请求模块在 node/io.js 中执行正确的 WebDAV PROPFIND 客户端请求? (或任何适用于此目的的东西。)
最佳答案
Node 和 iojs 中的出站请求支持 PROPFIND 或任何其他动词。您的请求或服务器上的配置存在其他问题(例如错误/错误的 header 或有效负载)。
PROPFIND 工作示例:
// client.js
require('http').request({
host: '127.0.0.1',
port: 8000,
method: 'PROPFIND'
}, function(res) {
res.resume();
}).end();
// server.js
require('http').createServer(function(req,res) {
// echoes "PROPFIND" to stdout
console.log(req.method);
res.writeHead(200, { 'Connection': 'close' });
res.end();
}).listen(8000);
关于javascript - Node.js:无法使用请求模块执行 PROFIND,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28899036/