this.http.get(url)
var headers = new Headers({'x-id': '1'}); this.http.get(url,{'headers': headers})
浏览器返回错误:
XMLHttpRequest cannot load http://domain/api/v1/. 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:3000' is therefore not allowed access.
我也尝试添加Origin头 – 浏览器错误:拒绝设置不安全标题“Origin”
和Access-Control-Allow-Origin标题 – 没有影响
在服务器(Laravel)上我创建了中间件Cors.PHP:
<?PHP namespace App\Http\Middleware; use Closure; class Cors { public function handle($request,Closure $next) { return $next($request) ->header('Access-Control-Allow-Origin','http://localhost:3000') ->header('Access-Control-Allow-Methods','GET,POST,PUT,DELETE,OPTIONS') ->header('Access-Control-Allow-Headers','x-id'); } }
Im new to angular2和CORS请求,不知道该怎么办.
>角度:2.0.0-beta.0
> Laravel:5.0
>浏览器:Google Chrome