节点js上的http GET请求出现问题 [英] Problem with http GET request on node js

查看:149
本文介绍了节点js上的http GET请求出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个http客户端,使用node.js从facebook上读取并使用以下代码:

Im writing an http client to read from facebook using node.js and using the following code:

var http = require('http');

var options = {
  host: 'www.fb.com',
  path: '/',
  "user-agent": "node.js"
};

http.get(options, function(res) {
  console.log("Got response: " + res.statusCode);
  console.log(res.headers);
}).on('error', function(e) {
console.log("Got error: " + e.message);
});

在我的浏览器中,这将返回301重定向,其中包含www.facebook.com的位置,但是node.js我得到了一个302响应,其位置为www.fb.com/common/browser.php。
我尝试使用最新版本的节点,它仍然会抛出此错误。

In my browser, this returns a 301 redirect with the location of www.facebook.com, however in node.js I get a 302 response with a location of www.fb.com/common/browser.php. I tried it with the latest version of node and it still throws this error.

我真的很感激一些帮助,
谢谢。

I'd really appreciate some help with this, Thanks.

推荐答案

这个剂似乎是node.js的一个bug我向curl的fb.com提出了一个请求我得到了相同的重定向。

This dosent seem to be a bug of node.js I made a request to fb.com in curl and I got the same redirect.

它可能基于用户代理做出决定...也许你可以使用浏览器的用户代理:D

It probably makes that decision based on the user agent... maybe you can use the user agent of a browser :D

这篇关于节点js上的http GET请求出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆