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 ...
随机推荐
- C#String详解
字符串:stringLength - 字符串的长度. TrimStart() 压缩空格即消除字符串开始空格TrimEnd() 消除结尾空格Trim() 同时消除开头和结尾空格.注:中间空格不消除,因为 ...
- 重定向redirect与跳转forward区别
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="DemoResponse.a ...
- Cheatsheet: 2013 11.12 ~ 11.30
Mobile Xcode 5 Essentials Android vs. iOS Development: Fight! Using MVC to Understand ASP.NET, iOS, ...
- CentOS 7 (无盘安装)PXE服务器的搭建(失败求助版)
折腾了一天半,PXE无盘服务器以暂时失败而告终. 基本原理 1. 首先客户端主机需要支持PXE,大部分主板都支持. 2. PXE服务器需要安装DHCP.TFTP.FTP服务. 3. DHCP服务用来给 ...
- CoreLocation
导入框架(Xcode5.0之后可以省略)
- C++中的一些定义
PS: 这篇博客用来记录一些一般的C++书中草草掠过的一些概念. 或者一些不太容易理解的概念的详细解释. 欢迎新手进入,欢迎高手指正! Orz . 引用: 为对象起了另外一个名字, 引用类型引用(re ...
- 简单模拟Spring管理Bean对象
1: 首先我们要利用dom4j进行xml的解析,将所有的bean的配置读取出来. 2:利用java的反射机制进行对象的实例化. 3: 直接获得对象 package cn.Junit.test; imp ...
- 企业信息化快速开发平台JeeSite
网站:http://jeesite.com/ 可用于企业后台管理
- velocity基础教程--1.标准使用(zhuan)
http://llying.iteye.com/blog/387253 **************************** velocity是一个非常好用的模板引擎 这里不对项目进行详细介绍,可 ...
- Java / JVM CPU 利用率高 - 诊断方法 1 - Thread Dump 结合 OS 诊断
IBM AIX Java 1. topas 命令定位 CPU 使用高的进程,比如下面 PID 614852 Name PID CPU% java 614852 ...