코딩하다가 local file에서 서버로 ajax요청할때 다음과 같은 에러발생함
[
Access to XMLHttpRequest at '[도메인1]' from origin '[도메인2 ,나같은 경우 file://]' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
]
알고보니 url(file:/// ~~~) 에서 url(http:// ~~)로 요청하니까
같은 origin 아니라고 차단하는거 같음
(http://[IP주소]:8080/[프로젝트]/[A.html]-웹주소가 이럴때 http://[IP주소]:8080/[프로젝트]/[B.ajax]-로 ajax요청 보내면 같은 호스트라서 문제없이 데이터를 보내줌)
해결방법
안드로이드 웹뷰
WebSettings webSettings = myWebView.getSettings();
webSettings.setAllowFileAccess(true);
webSettings.setAllowContentAccess(true);
webSettings.setAllowFileAccessFromFileURLs(true);
webSettings.setAllowUniversalAccessFromFileURLs(true);
크롬 - 플러그인 설치(확장프로그램가서 cors치면나옴)
Spring-MVC(모든요청허락)
4.2 버젼 이후부터
@CrossOrigin 어노테이션 쓰면됨.
댓글 없음:
댓글 쓰기