鍍金池/ 問答/網(wǎng)絡(luò)安全  HTML/ nodejs調(diào)用第三方 API,一般用哪些框架呢?

nodejs調(diào)用第三方 API,一般用哪些框架呢?

現(xiàn)在vue項(xiàng)目里面需要調(diào)用(每5s調(diào)用一次)第三方提供的 api,需要模擬 http 請(qǐng)求,然后得到 json 結(jié)果,這個(gè)大家一般用什么前端框架呢?還是自己封裝一個(gè)http模塊呢?

如下(網(wǎng)上找的一段代碼)

var http = require("http");  
  
var data = {username:"hello",password:"123456"};  
data = JSON.stringify(data);  
//data = require('querystring').stringify(data);  
  
var opt = {  
    host:'localhost',  
    port:'8080',  
    method:'POST',  
    path:'/loginForeign.jspx',  
    headers:{  
        "Content-Type": 'application/json',  
        "Content-Length": data.length  
    }  
}  
  
var body = '';  
var req = http.request(opt, function(res) {  
    console.log("response: " + res.statusCode);  
    res.on('data',function(data){  
        body += data;  
    }).on('end', function(){  
        console.log(body)  
    });  
}).on('error', function(e) {  
    console.log("error: " + e.message);  
})  
req.write(data);  
req.end();  
回答
編輯回答
懶豬
2017年1月14日 11:14
編輯回答
雨萌萌

axios,request

2017年10月6日 22:16