programing

축삭의 교차 영역

telecom 2023. 10. 7. 09:25
반응형

축삭의 교차 영역

axios용 jquery ajax를 변경하는데 크로스 도메인이 있는 axios를 사용할 수 없습니다.

axios.get(myurl, {
            headers: { 'crossDomain': true },
        }).then(res => { 
            console.log(res);

        }).catch(error => {
            console.log('erro', error);
        })

jquery 코드가 작동 중입니다.

$.ajax({
   type: 'GET',
   crossDomain: true,
   url:myurl,
   success: (res) => {},
   error: (fail) => {}     
})

오류: Request Header 필드 crossDomain이 비행 전 응답에서 Access-Control-Allow-Headers에 의해 허용되지 않습니다.

누가 나를 도와줄 수 있나요?

"crossDomain"은 헤더에 있을 필요가 없습니다.

axios.get(myurl, {
    crossDomain: true
}).then(res => { 
    console.log(res);
}).catch(error => {
    console.log('error', error);
})

안부 전해요

나의 경우 @nuxtjs/proxy 해결된 문제

https://nuxtjs.org/faq/http-proxy/

nuxt.config.js에 @nuxtjs/proxy를 삽입하고 프록시 설정을 편집했습니다.

api server와 rest api를 사용했습니다.

proxy: {
'/api': {
  target: 'http://127.0.0.1:8080',
  pathRewrite: {
    '^/api' : '/api'
    },
},
'/zip': {
  target: 'http://zipcloud.ibsnet.co.jp',
  pathRewrite: {
    '^/zip' : '/api'
    }
}
}

언급URL : https://stackoverflow.com/questions/42422494/cross-domain-at-axios

반응형