Laravel 5.3 API가 구성되었습니다
<code> //category.service.ts private headers = new Headers({'Content-Type': 'application/json','Accept':'application/json','Authorization':'Bearer '+window.localStorage.getItem('token')}); private heroesUrl = 'http://xingao.5188cms.com/api/user'; // URL to web api private handleError(error: any): Promise<any> { console.error('An error occurred', error); // for demo purposes only return Promise.reject(error.message || error); } </code>
이렇게 접속하면 XMLHttpRequest cannot load http://xingao.5188cms.com/api/user. 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:8100' is therefore not allowed access.
라는 메시지가 뜹니다. 크로스도메인 문제인 것 같은데, postman을 이용해서 데이터를 성공적으로 가져왔습니다
링크를 하나로 바꿨습니다http://xingao.5188cms.com/test.php
<code>//test.php <?php header("Access-Control-Allow-Origin: *"); $arr=['1','2']; echo json_encode($arr); ?></code>
아직 작동하지 않습니다XMLHttpRequest cannot load http://xingao.5188cms.com/test.php. Request header field authorization is not allowed by Access-Control-Allow-Headers in preflight response.
링크를 /test.json
으로 변경했는데 작동합니다
이유는 무엇인가요? . . .
Laravel 5.3 API가 구성되었습니다
<code> //category.service.ts private headers = new Headers({'Content-Type': 'application/json','Accept':'application/json','Authorization':'Bearer '+window.localStorage.getItem('token')}); private heroesUrl = 'http://xingao.5188cms.com/api/user'; // URL to web api private handleError(error: any): Promise<any> { console.error('An error occurred', error); // for demo purposes only return Promise.reject(error.message || error); } </code>
이렇게 접속하면 XMLHttpRequest cannot load http://xingao.5188cms.com/api/user. 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:8100' is therefore not allowed access.
라는 메시지가 뜹니다. 크로스도메인 문제인 것 같은데, postman을 이용해서 데이터를 성공적으로 가져왔습니다
링크를 하나로 바꿨습니다 http://xingao.5188cms.com/test.php
<code>//test.php <?php header("Access-Control-Allow-Origin: *"); $arr=['1','2']; echo json_encode($arr); ?></code>
아직 작동하지 않습니다XMLHttpRequest cannot load http://xingao.5188cms.com/test.php. Request header field authorization is not allowed by Access-Control-Allow-Headers in preflight response.
링크를 /test.json
으로 변경했는데 작동합니다
이유는 무엇인가요? . . .
Access-Control-Allow-Origin
교차 도메인 문제
브라우저의 한계입니다