获取HTTP标头使用的是Node.js
是否有一个内置的方式通过node.js中获取特定地址的头?
就像是,
var headers = getUrlHeaders("");
将返回
HTTP/1.1 200 OK.
Cache-Control: public, max-age=60.
Content-Type: text/html; charset=utf-8.
Content-Encoding: gzip.
Expires: Sat, 07 May 2011 17:32:38 GMT.
Last-Modified: Sat, 07 May 2011 17:31:38 GMT.
Vary: *.
Date: Sat, 07 May 2011 17:31:37 GMT.
Content-Length: 32516.
回答如下:
此示例代码应工作:
var http = require('http');
var options = {method: 'HEAD', host: 'stackoverflow', port: 80, path: '/'};
var req = http.request(options, function(res) {
console.log(JSON.stringify(res.headers));
}
);
req.end();
获取HTTP标头使用的是Node.js
是否有一个内置的方式通过node.js中获取特定地址的头?
就像是,
var headers = getUrlHeaders("");
将返回
HTTP/1.1 200 OK.
Cache-Control: public, max-age=60.
Content-Type: text/html; charset=utf-8.
Content-Encoding: gzip.
Expires: Sat, 07 May 2011 17:32:38 GMT.
Last-Modified: Sat, 07 May 2011 17:31:38 GMT.
Vary: *.
Date: Sat, 07 May 2011 17:31:37 GMT.
Content-Length: 32516.
回答如下:
此示例代码应工作:
var http = require('http');
var options = {method: 'HEAD', host: 'stackoverflow', port: 80, path: '/'};
var req = http.request(options, function(res) {
console.log(JSON.stringify(res.headers));
}
);
req.end();