nodeschool.io 7
~~ HTTP CLIENT ~~
Write a program that performs an HTTP GET request to a URL provided to
you as the first command-line argument. Write the String contents of
each "data" event from the response to a new line on the console
(stdout).
----------------------------------------------------------------------
HINTS:
For this exercise you will need to use the `http` core module.
Documentation on the `http` module can be found by pointing your
browser here:
C:\Users\dzhang\AppData\Roaming\npm\node_modules\learnyounode\node_apidoc\http
.html
The `http.get()` method is a shortcut for simple GET requests, use it
to simplify your solution. The first argument to `http.get()` can be
the URL you want to GET, provide a callback as the second argument.
Unlike other callback functions, this one has the signature:
function (response) { ... }
Where the `response` object is a Node Stream object. You can treat Node
Streams as objects that emit events, the three events that are of most
interest are: "data", "error" and "end". You listen to an event like
so:
stream.on("data", function (data) { ... })
The "data" is emitted when a chunk of data is available and can be
processed. The size of the chunk depends upon the underlying data
source.
The `response` object / Stream that you get from `http.get()` also has
a `setEncoding()` method. If you call this method with "utf8", the
"data" events will emit Strings rather than the standard Node `Buffer`
objects which you have to explicitly convert to Strings.
----------------------------------------------------------------------
httpClient.js(nodejs api里面找了找,啊哈哈哈)
var http = require('http');
http.get(process.argv[2], function(res) {
res.setEncoding('utf8');
res.on('data', function (chunk) {
console.log(chunk);
});
});
nodeschool.io 7的更多相关文章
- nodeschool.io 4
~~ MY FIRST ASYNC I/O! ~~ Write a program that uses a single asynchronous filesystem operationto rea ...
- nodeschool.io 3
~~ MY FIRST I/O! ~~ Write a program that uses a single synchronous filesystem operation toread a fil ...
- nodeschool.io 2
~~ BABY STEPS ~~ Write a program that accepts one or more numbers as command-line arguments and pr ...
- nodeschool.io 10
~~ TIME SERVER ~~ Write a TCP time server! Your server should listen to TCP connections on port 8000 ...
- nodeschool.io 9
~~ JUGGLING ASYNC ~~ 其实就是一个循环,在循环里面输出的顺序,和排列后在外面的顺序不一样,这是为什么呢? 用第三方async包,直接报错了…… This problem is th ...
- nodeschool.io 8
~~ HTTP COLLECT ~~ Write a program that performs an HTTP GET request to a URL provided toyou as the ...
- nodeschool.io 6
~~ MAKE IT MODULAR ~~ This problem is the same as the previous but introduces the concept ofmodules. ...
- nodeschool.io 5
~~ FILTERED LS ~~ Create a program that prints a list of files in a given directory,filtered by the ...
- NODESCHOOL
来源:https://nodeschool.io/zh-cn/ 核心基础课程(Core) javascripting 学习 JavaScript 语言的基础,无需任何编程经验 npm install ...
随机推荐
- SqlSever基础 union 与 union all的区别,即 重复项是否全部显示
镇场诗:---大梦谁觉,水月中建博客.百千磨难,才知世事无常.---今持佛语,技术无量愿学.愿尽所学,铸一良心博客.------------------------------------------ ...
- (1)创建一个叫做机动车的类: 属性:车牌号(String),车速(int),载重量(double) 功能:加速(车速自增)、减速(车速自减)、修改车牌号,查询车的载重量。 编写两个构造方法:一个没有形参,在方法中将车牌号设置“XX1234”,速 度设置为100,载重量设置为100;另一个能为对象的所有属性赋值; (2)创建主类: 在主类中创建两个机动车对象。
package a; public class Jidongche { private String chepaihao; private int chesu; private double zaiz ...
- PHP工作原理
文章一 :http://blog.csdn.net/21aspnet/article/details/6973405 简介 先看看下面这个过程: 我们从未手动开启过PHP的相关进程,它是随着Apach ...
- [51NOD1959]循环数组最大子段和(dp,思路)
题目链接:http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1050 这道题的最大子段和有两种可能,一种是常规的子段和,另一种 ...
- oracle命令识记
连接数据库 sqlplus /nolog; conn / as sysdba; set ORACLE_SID=实例名; 查看表结构命令 select table_name from user_tabl ...
- linux远程XP
众所周知XP下有"远程桌面连接"用来远程登录桌面,设置也非常简单. 那有没有什么办法在linux下远程登录到XP呢?有.用rdesktop这个linux下的软件就能实现. 发现新立 ...
- SQL行转列
目的:将相同条件的多行值合并到同一列, 1.创建测试表: CREATE TABLE [dbo].[TB_01]( ) NULL, ) NULL, [SDATE] [datetime] NULL ) O ...
- POJ 3461 Oulipo(乌力波)
POJ 3461 Oulipo(乌力波) Time Limit: 1000MS Memory Limit: 65536K [Description] [题目描述] The French autho ...
- Linux基础01 学会使用命令帮助
Linux基础01 学会使用命令帮助 概述 在linux终端,面对命令不知道怎么用,或不记得命令的拼写及参数时,我们需要求助于系统的帮助文档:linux系统内置的帮助文档很详细,通常能解决我们的问题, ...
- return、 return false的用法
1. return返回null,起到中断方法执行的效果,只要不return false事件处理函数将会继续执行,表单将提交2. return false,事件处理函数会取消事件,不再继续向下执行.比如 ...