Node.js模块 —— request
一、安装
npm install --save request
二、GET方法
const request = require('request'); request('url', function (error, response, body) { if (!error && response.statusCode == 200) { console.log(body); } });
三、POST方法
const request = require('request'); request({ url: url, method: "POST", json: true, headers: { "content-type": "application/json", }, body: JSON.stringify(requestData) }, function(error, response, body) { if (!error && response.statusCode == 200) { console.log(body) } });
四、FORM
request.post({url:'', form:{key:'value'}}, function(error, response, body) { if (!error && response.statusCode == 200) { console.log(body) } })