最新消息: 电脑我帮您提供丰富的电脑知识,编程学习,软件下载,win7系统下载。

获取HTTP标头使用的是Node.js

IT培训 admin 5浏览 0评论

获取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();

与本文相关的文章

发布评论

评论列表 (0)

  1. 暂无评论