当前位置:首页 > 编程开发

5 Ways to Make HTTP Requests in Node.js

webgou5年前 (2021-12-04)编程开发91

 来源:https://www.twilio.com/blog/2017/08/http-requests-in-node-js.html

HTTP – the Standard Library

First on our hit parade is the default HTTP module in the standard library. With this module, you can just plug and go without having to install external dependencies. The downside is that it isn’t very user friendly compared to other solutions.

The following code will send a GET request to NASA’s API and print out the URL for the astronomy picture of the day as well as an explanation:

 

const https = require('https');  https.get('https://api.nasa.gov/planetary/apod?api_key=DEMO_KEY', (resp) => {   let data = '';    // A chunk of data has been received.   resp.on('data', (chunk) => {     data += chunk;   });    // The whole response has been received. Print out the result.   resp.on('end', () => {     console.log(JSON.parse(data).explanation);   });  }).on("error", (err) => {   console.log("Error: " + err.message); });

扫描二维码推送至手机访问。

版权声明:本文由知了博客发布,如需转载请注明出处。

本文链接:https://www.webgou.info/?id=665

分享给朋友:

“5 Ways to Make HTTP Requests in Node.js” 的相关文章

Android创建sdcard详细图解

Android创建sdcard步骤一、cmd进入tools目录输入mksdcard -l mycard 100M F:\mysdcard.img 1. mycard命令可以使用三种尺寸:字节、K和M。如果只使用数字,表示字节。后面还可以跟K,如262144K,也表示256M。2. mycard建立的…

ARM寄存器简介

ARM寄存器介绍 ARM处理器共有37个寄存器。其中包括:31个通用寄存器,包括程序计数器(PC)在内。这些寄存器都是32位寄存器。以及6个32位状态寄存器。但目前只使用了其中12位。ARM处理器共有7种不同的处理器模式,在每一种处理器模式中有一组相应的寄存器组。任意时刻(也就是任意的处理器模式下)…

Android应用技巧总结

1.Drawable的使用最经常会处理Drawable作为类型的资源回收绘制到屏幕上的东西; Drawable类提供了一个通用的API来处理一个基本的视觉资源,可以采取多种形式。(讲的有点抽象)讲白点就是获取res下的参数例:改变TextView文字颜色-引用Drawable颜色常熟及背景色valu…

eclipse插件的三种安装方法

1、将插件直接拷贝到eclipse的plugins(有时候还包括features)目录下,然后重启一下eclipse,在eclipse的插件库中 (--˃Help-˃SoftWare Updates-˃Manager Configuration)就可以找到。重启的时候可以清除一下eclipse的缓存…

the uml of gof

gang of four `s uml…

Unity反编译备忘录

1. disunity+disunityGUI编译后可执行文件地址:https://github.com/ata4/disunity/releasesdisunity在github源码地址:https://github.com/ata4/disunity 2.DevXUnity-Unpac…

发表评论

访客

看不清,换一张

◎欢迎参与讨论,请在这里发表您的看法和观点。