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 ...
随机推荐
- sql 集合运算
UNION 并运算 UNION 操作符用于合并两个或多个 SELECT 语句的结果集. 请注意,UNION 内部的 SELECT 语句必须拥有相同数量的列.列也必须拥有相似的数据类型.同时,每条 SE ...
- CSS属性前的 -webkit, -moz,-ms,-o
-moz-对应 Firefox, -webkit-对应 Safari and Chrome-o- for Opera-ms- for Internet Explorer(microsoft) 在CSS ...
- Change Or Set Report Object Property At Run Time In Oracle Forms Using Set_Report_Object_Property Command
Sets the Report object property at run time in Oracle Forms of an report object. The following are t ...
- Perform Cut Copy Paste Operations Using Cut_Region Copy_Region Paste_Region Commands In Oracle Forms
You can do Select, Cut, Copy and Paste operations on text items in Oracle Forms using Select_All, Cu ...
- CUBRID学习笔记 22 插入数据
CREATE TABLE auto_tbl(id INT AUTO_INCREMENT, name VARCHAR); 自增长的列可以插入null, 同时一次可以插入多条记录.别的和其他的sql数据库 ...
- Jenkins插件及 测试源码
Jenkins 插件: https://updates.jenkins-ci.org/download/plugins/ 小米的一份android源码,测试工具,用于抢红包: https://gith ...
- 详解C#委托,事件与回调函数
.Net编程中最经常用的元素,事件必然是其中之一.无论在ASP.NET还是WINFrom开发中,窗体加载(Load),绘制(Paint),初始化(Init)等等.“protected void Pag ...
- js 定时器的使用。 setInterval()
我需要实现的功能是:点击发送按钮,会出现 “已发送60s后可点击重发”,并且,60s 这个数字是随时变化的,60,59,58,57....0,然后再次返回到 发送 按钮. 类似效果,可参考 360首 ...
- 四十条测试你是不是合格的PHP程序员
四十条测试你是否合格的PHP程序员,不官方,也不权威,但很给力.超过三条就不合格了.超过五条就得好好反省下自己的不足了. 1. 不会利用如phpDoc这样的工具来恰当地注释你的代码 2. 对优秀的集成 ...
- 团队作业Week5之团队贡献分的分配
一.团队贡献分的分配规则 首先,我们团队共有5个人,平均每个人50分,所以我们团队的总分为5*50=250,我们先把50分分成以下几份: 序号 贡献类型 权重 分数 1 代码贡献 40% 20 * 5 ...