博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
[Node.js]27. Level 5: URL Building & Doing the Request
阅读量:5113 次
发布时间:2019-06-13

本文共 1124 字,大约阅读时间需要 3 分钟。

Let's create a page which calls the twitter search API and displays the last few results for Code School. The first step is to construct the proper URL, which is all you need to do in this challenge.

Complete the URL options which will be sent into the the url module's  method. The URL you'll want to construct is the following:

var url = require('url');options = {  // add URL options here  protocol: "http",  host: 'search.twitter.com',  pathname: '/search.json',  query: {q: "codeschool"}};var searchURL = url.format(options);console.log(searchURL);

 

Next we'll need to include the  module, use that to do a simple web request, and print the returned JSON out to the console. You'll want to check out  in the readme.

var url = require('url');var request = require('request');options = {  protocol: "http:",  host: "search.twitter.com",  pathname: '/search.json',  query: { q: "codeschool"}};var searchURL = url.format(options);request(searchURL, function(err, res, body){  if (!err && res.statusCode == 200) {    console.log(body) // Print the google web page.  }    });

 

转载于:https://www.cnblogs.com/Answer1215/p/3881186.html

你可能感兴趣的文章
Android 官方新手指导教程
查看>>
幸运转盘v1.0 【附视频】我的Android原创处女作,请支持!
查看>>
UseIIS
查看>>
集合体系
查看>>
vi命令提示:Terminal too wide
查看>>
引用 移植Linux到s3c2410上
查看>>
人与人之间的差距是从大学开始的
查看>>
MySQL5.7开多实例指导
查看>>
[51nod] 1199 Money out of Thin Air #线段树+DFS序
查看>>
poj1201 查分约束系统
查看>>
Red and Black(poj-1979)
查看>>
分布式锁的思路以及实现分析
查看>>
腾讯元对象存储之文件删除
查看>>
jdk环境变量配置
查看>>
安装 Express
查看>>
包含列的索引:SQL Server索引的阶梯级别5
查看>>
myeclipse插件安装
查看>>
浙江省第十二届省赛 Beauty of Array(思维题)
查看>>
NOIP2013 提高组 Day1
查看>>
个人对vue生命周期的理解
查看>>