/*
https://github.com/request/request
Request is designed to be the simplest way possible to make http calls.
It supports HTTPS and follows redirects by default.
notice: request返回不是Promise(axios发请求返回的就是Promise)
*/const request =require('request');request('http://www.google.com',function(error, response, body){
console.error('error:', error);// Print the error if one occurred
console.log('statusCode:', response && response.statusCode);// Print the response status code if a response was received
console.log('body:', body);// Print the HTML for the Google homepage.});
1. 直接用 request封装好的Promise版, request-promise
npm install --save request-promise
2. 自己封装一个
// 封装constasync_request=(url)=>{returnnewPromise((resolve, reject)=>{
request.get(url,function(err, res){if(err){reject(err);}else{resolve(res);}});})};// 调用const test =async(url)=>{awaitasync_request(url);};