nodejs request模块

xiaoxiao2021-02-27  386

安装命令:

npm install --save request

使用简单例子: get方法:

var request = require('request'); request('您的请求url', function (error, response, body) { if (!error && response.statusCode == 200) { console.log(body) // 请求成功的处理逻辑 } });

post方法:

var request = require('request'); var url="请求url"; var requestData="上送的数据"; 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) // 请求成功的处理逻辑 } });

post form:

request.post({url:'', form:{key:'value'}}, function(error, response, body) { if (!error && response.statusCode == 200) { console.log(body) // 请求成功的处理逻辑 } })
转载请注明原文地址: https://www.6miu.com/read-3723.html

最新回复(0)