您好,欢迎访问一九零五行业门户网

ionic2/angular2 不能访问laravel5.3 创建的api

laravel 5.3 api已经配置完成了
//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 { console.error('an error occurred', error); // for demo purposes only return promise.reject(error.message || error); }

这样去访问,提示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
//test.php

还是不行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已经配置完成了
//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 { console.error('an error occurred', error); // for demo purposes only return promise.reject(error.message || error); }

这样去访问,提示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
//test.php

还是不行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
跨域的问题
这是浏览器的限制
其它类似信息

推荐信息