zoukankan      html  css  js  c++  java
  • 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:UsersdzhangAppDataRoaming pm ode_moduleslearnyounode ode_apidochttp
    .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);
      });
    });
  • 相关阅读:
    Win7 64位系统上Hadoop单机模式的安装及开发环境搭建
    HBase配置文件设置
    YARN HA 配置文件设置
    Hadoop的配置文件设置(HDFS HA)
    记一次java heap space的解决办法
    记一次sql优化——left join不走索引问题
    js黑魔法
    css坑了我一下下之line-height
    target-densitydpi=device-dpi会使其他ui插件布局变小
    redis缓存过期key优化-缓存不释放
  • 原文地址:https://www.cnblogs.com/della/p/3430220.html
Copyright © 2011-2022 走看看