使用Express获取Node.js中的URL内容 [英] Get URL Contents in Node.js with Express

查看:114
本文介绍了使用Express获取Node.js中的URL内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Express框架时,如何在Node中下载URL的内容?基本上,我需要完成Facebook身份验证流程,但是如果没有访问其OAuth令牌URL,我将无法执行此操作。

How would I go about downloading the contents of a URL in Node when using the Express framework? Basically, I need to complete the Facebook authentication flow, but I can't do this without GETing their OAuth Token URL.

通常,在PHP中,我会使用Curl,但是Node相当于什么?

Normally, in PHP, I'd use Curl, but what is the Node equivalent?

推荐答案

var options = {
  host: 'www.google.com',
  port: 80,
  path: '/index.html'
};

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

http://nodejs.org/docs/v0.4.11/api/http.html#http.get

这篇关于使用Express获取Node.js中的URL内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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