1
0
Code Issues Pull Requests Projects Releases Wiki Activity GitHub Gitee

一些测试用的代码

This commit is contained in:
程序员小墨 2022-07-29 17:24:34 +08:00
parent dd9e72e16a
commit a521758cfa
2 changed files with 73 additions and 0 deletions

31
测试请求API接口.js Normal file
View File

@ -0,0 +1,31 @@
const request = require('request');
let url = 'https://api.bilibili.com/x/web-interface/ranking/v2?type=all';
// 请求 APi 接口
async function getApiResult(url) {
var return_data = await new Promise((resolve) => {
request({
method: 'GET',
url: url,
}, (error, response, result) => {
console.log("error, response, result", error, response, result);
if (!error && (response.statusCode == 200)) {
// 请求成功
resolve(result);
} else {
// 请求失败
console.log(`error is ${error}`);
resolve("error");
}
});
});
// console.log(`return_data is ${JSON.stringify(return_data)}`);
return return_data;
}
async function main() {
let result = await getApiResult(url);
console.log(result);
}
main();

File diff suppressed because one or more lines are too long