下面是我的index.js文件
我正在尝试从体育数据API中获取回复。我可以毫不费力地发出卷曲请求,但是当我尝试这样做时,我收到了一个禁止的403错误。
var express = require('express');
var config = require("../config.js");
var superagent = require("superagent");
var router = express.Router();
var timer = require('timers');
var isInitialized = false;
var isUpdating = false;
var timerId;
var admin;
var db;
var games = {};
var ref; //games ref to realtime database
/* GET home page. */
router.get('/index', function(req, res, next) {
console.log(req.query);
startUpdate();
res.render('index', { title: 'CBB update' , isUpdating: isUpdating});
});
router.get('/', function(req, res, next) {
console.log(req.query);
res.render('index', { title: 'Express' , isUpdating: isUpdating});
});
};
for(var id in games){
var fantasyUrl = 'https://api.sportradar.us/ncaamb-t3/games/' + games[id].gameID + '/boxscore.json?api_key='+ config.fantasy.primaryKey;
const uid = id;
var request = superagent.get(fantasyUrl)
.set('X-Originating-Ip', '73.60.233.133')
.end(function(err, res){
if(err){
console.log(err);
return;
}
};
以下是我的终端输出
{ Error: Forbidden
at Request.callback (/Users/nishonradhakrishnan/Desktop/bettorhalf-sportradar/node_modules/superagent/lib/node/index.js:674:11)
at IncomingMessage.<anonymous> (/Users/nishonradhakrishnan/Desktop/bettorhalf-sportradar/node_modules/superagent/lib/node/index.js:881:18)
at emitNone (events.js:91:20)
at IncomingMessage.emit (events.js:188:7)
at endReadableNT (_stream_readable.js:974:12)
at _combinedTickCallback (internal/process/next_tick.js:80:11)
at process._tickCallback (internal/process/next_tick.js:104:9)
status: 403,
response:
Response {
domain: null,
_events: {},
_eventsCount: 0,
_maxListeners: undefined,
res:
IncomingMessage {
_readableState: [Object],
readable: false,
domain: null,
_events: [Object],
_eventsCount: 4,
_maxListeners: undefined,
socket: [Object],
connection: [Object],
httpVersionMajor: 1,
httpVersionMinor: 1,
httpVersion: '1.1',
complete: true,
headers: [Object],
rawHeaders: [Object],
trailers: {},
rawTrailers: [],
upgrade: false,
url: '',
method: null,
statusCode: 403,
statusMessage: 'Forbidden',
client: [Object],
_consuming: true,
_dumped: false,
req: [Object],
text: '<h1>Developer Over Qps</h1>',
read: [Function] },
答案 0 :(得分:0)
fantasyUrl
变量错误,您不需要以https://api.sportradar.us