鍍金池/ 問答/網絡安全  HTML/ nodejs調用第三方 API,一般用哪些框架呢?

nodejs調用第三方 API,一般用哪些框架呢?

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

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

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