尝试使用 Vue.js 访问 Stack Overflow Api 时出错
Trying to access Stack Oveflow Api using Vue.js getting error
控制台错误:
重现错误的代码:
var request = require('request');
var url = 'http://api.stackexchange.com/2.2/https://whosebug.com/questions';
request({
headers: {
'Accept': 'application/json; charset=utf-8',
'User-Agent': 'RandomHeader'
},
uri: url,
key: 'cawQTENGI5TpoSgBKy7SXw',
method: 'GET',
gzip: true
},
function(err, res, body) {
console.log("response.statusCode" + res.statusCode);
console.log('server encoded the data as: ' + (res.headers['content-encoding'] || 'identity'))
console.log('the decoded data is: ' + body)
});
export default {
name: 'StackApi',
}
我的本意是把所有的问题都问完,但是Stack Overflow的文档对我来说很难理解,是不是因为我是在本地访问数据?我不明白跨源读取阻塞。
你用错了url
var url = 'http://api.stackexchange.com/2.2/https://whosebug.com/questions';
应该是:
var url 'http://api.stackexchange.com//2.2/questions?order=desc&sort=activity&site=Whosebug'
只需在您的查询中提供网站名称
控制台错误:
重现错误的代码:
var request = require('request');
var url = 'http://api.stackexchange.com/2.2/https://whosebug.com/questions';
request({
headers: {
'Accept': 'application/json; charset=utf-8',
'User-Agent': 'RandomHeader'
},
uri: url,
key: 'cawQTENGI5TpoSgBKy7SXw',
method: 'GET',
gzip: true
},
function(err, res, body) {
console.log("response.statusCode" + res.statusCode);
console.log('server encoded the data as: ' + (res.headers['content-encoding'] || 'identity'))
console.log('the decoded data is: ' + body)
});
export default {
name: 'StackApi',
}
我的本意是把所有的问题都问完,但是Stack Overflow的文档对我来说很难理解,是不是因为我是在本地访问数据?我不明白跨源读取阻塞。
你用错了url
var url = 'http://api.stackexchange.com/2.2/https://whosebug.com/questions';
应该是:
var url 'http://api.stackexchange.com//2.2/questions?order=desc&sort=activity&site=Whosebug'
只需在您的查询中提供网站名称