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 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 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
跨域的問題
這是瀏覽器的限制