Node.js http.get请求从curl请求获取一组完全不同的头

Node.js http.get请求从curl请求获取一组完全不同的头,node.js,redirect,curl,Node.js,Redirect,Curl,好的,我正在尝试获取这个特定URL的标题,node.js的行为让我感到困惑 我的代码: var http = require('http'); var req = http.get("http://listen.radionomy.com/abc-lounge", function(res) { console.log("headers: ", res.headers); }); 打印出: 标题:{'cache-control':'private','content-type':'t

好的,我正在尝试获取这个特定URL的标题,node.js的行为让我感到困惑

我的代码:

var http = require('http');

var req = http.get("http://listen.radionomy.com/abc-lounge", function(res) {
   console.log("headers: ", res.headers); 
});
打印出:

标题:{'cache-control':'private','content-type':'text/html; 字符集=utf-8',服务器:'Microsoft IIS/7.5','x-aspnet-version': “4.0.30319”、“x-powered-by”:“ASP.NET”,日期:2014年1月28日星期二 格林尼治标准时间14:18:27,“内容长度”:“8309”}

现在我试用了带有标题的命令行curl:

curl-I

这正好打印出我要查找的内容(重定向url):

找到HTTP/1.1 302缓存控制:专用
内容长度: 0
内容类型:应用程序/八位字节流
位置:
服务器: Microsoft IIS/7.5
X-AspNetMvc-Version:5.0
X-AspNet-Version: 4.0.30319
X-Powered-By:ASP.NET
日期:2014年1月28日星期二14:19:20 GMT


我不明白node为什么会得到一组不同的头。默认情况下,它不应遵循重定向。我甚至不认为这是一个重定向问题。

这是因为
http.get
实际上遵循重定向我通过向
http添加一些
头来伪造
curl
请求。get
如下所示:

var http = require('http');

var options = {
    host: 'listen.radionomy.com',
    path: '/abc-lounge',
    headers: {
        'user-agent': 'curl/7.31.0',
        'accept': '*/*'         
    }
};

var req = http.get(options, function(res) {
   console.log('status:', res.statusCode)
   console.log("headers: ", res.headers); 
});
status: 302
headers:  { 'cache-control': 'private',
  'content-type': 'application/octet-stream',
  location: 'http://streaming.radionomy.com/ABC-Lounge',
  server: 'Microsoft-IIS/7.5',
  'x-aspnetmvc-version': '5.0',
  'x-aspnet-version': '4.0.30319',
  'x-powered-by': 'ASP.NET',
  date: 'Tue, 28 Jan 2014 15:02:16 GMT',
  'content-length': '0' }
输出将为:

var http = require('http');

var options = {
    host: 'listen.radionomy.com',
    path: '/abc-lounge',
    headers: {
        'user-agent': 'curl/7.31.0',
        'accept': '*/*'         
    }
};

var req = http.get(options, function(res) {
   console.log('status:', res.statusCode)
   console.log("headers: ", res.headers); 
});
status: 302
headers:  { 'cache-control': 'private',
  'content-type': 'application/octet-stream',
  location: 'http://streaming.radionomy.com/ABC-Lounge',
  server: 'Microsoft-IIS/7.5',
  'x-aspnetmvc-version': '5.0',
  'x-aspnet-version': '4.0.30319',
  'x-powered-by': 'ASP.NET',
  date: 'Tue, 28 Jan 2014 15:02:16 GMT',
  'content-length': '0' }

节点的
http.get()
不应跟随。正在尝试SO的“共享”链接,其中包括日志中的
位置:'/questions/…'
。谢谢,这很有帮助。奇怪的是,如果您没有传递“用户代理”,那么listen.radionomy.com会用一组不同的标题回答您。这里的节点没有问题,就像我认为这不是重定向问题一样。