Node.js从服务器主动发送请求
服务器请求百度首页 参考文档 链接 //服务器发送请求 const http = require ( 'http' ) ; const path = require ( 'path' ) ; const fs = require ( 'fs' ) ; let options = { hostname : 'www.baidu.com' , port : '80' } let req = http . request ( options , ( res ) => { let info = '' ; res . on ( 'data' , ( chunk ) => { info += chunk ; } ) res . on ( 'end' , ( ) => { fs . writeFile ( path . join ( __dirname , 'baidu.html' ) , info , ( err ) => { if ( ! err ) { console . log ( "百度主页html内容加载完毕" ) } } ) } ) } ) req . end ( ) ; 服务器向后台接口发送请求 查询数据 const http = require ( 'http' ) ; let options = { protocol : 'http:' , hostname :