밋업 API에서 응답을받는 데 약간의 어려움이 있습니다. 내가 얻는 오류 :
Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8080' is therefore not allowed access.
내 코드는 다음과 같습니다.
var config = {'Access-Control-Allow-Headers': 'Authorization'}
axios.get(`https://api.meetup.com/self/calendar?&sign=true&photo-host=public&page=20`, {headers: config})
.then(response => {
console.log(response.data)
this.posts = response.data
})
.catch(e => {
this.errors.push(e)
})
여기서 CORS에 대해 조금 읽었 지만 CORS (Cross-Origin Resource Sharing)를 사용 하려는 모든 시도가 실패했습니다.
누구든지 이것에 대해 밝힐 수 있습니까?
감사,
마누
맞습니다. 이제 작동합니다. @FailedUnitTest 및 @Manav Mandal 제안 모두 고려할 가치가 있습니다. 그러나 OAuth 를 사용하는 대신 API 키를 사용할 수 있습니다 . 또한 내 프록시는 내 expressJS 서버입니다.
서버 측에서는 다음과 같은 내용이있을 것입니다.
var express = require('express');
var axios = require('axios');
// meetup API
var instance = axios.create({
baseURL: 'https://api.meetup.com/'
});
app.get('/anything', function(req, res) {
const apiKey = 'yourKey';
const isSigned = 'true';
const photoHost = 'public';
const pageCount = '20';
const url = '/self/calendar?' + 'key=' + apiKey + '&sign=' + isSigned
+ '&photo-host=' + photoHost + '&page=' + pageCount + '';
instance.get(url)
.then(response => {
return res.send(response.data);
})
.catch(e => {
return e;
})
});
그리고 클라이언트 측 :
data () {
return {
cards: [],
errors: []
};
},
created () {
axios.get('/anything')
.then(response => {
this.cards = response.data;
})
.catch(e => {
this.errors.push(e);
});
}
서버와 클라이언트가 모두 동일한 포트에서 실행되는지 확인하십시오 .
문안 인사,
마누
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다