2017-01-05 39 views
2

我有这片Vue.js的:CORS失败的POST请求

... 
this.$http.post('http://localhost:8000/oauth/token', postData) 
    .then(response => { 
    console.log(response) 
}) 
this.$http.get('http://localhost:8000/api/test') 
    .then(response => { 
    console.log(response) 
}) 
... 

最后一个GET请求工作正常,但文章没有通过,由于去

的XMLHttpRequest无法加载http://localhost:8000/oauth/token。对预检请求的响应不会通过访问控制检查:请求的资源上不存在“Access-Control-Allow-Origin”标头。产地......

我Cors.php中间件:

... 
public function handle($request, Closure $next) 
{ 
    return $next($request) 
     ->header('Access-Control-Allow-Origin', '*') 
     ->header('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, OPTIONS'); 
} 
... 

Kernel.php:

... 

    'api' => [ 
     'throttle:60,1', 
     'bindings', 
     \App\Http\Middleware\Cors::class, 
    ], 
... 

我已经做了php artisan route:list我注意到,该航线...oauth/token具有中间件throttle,它是唯一一个默认的...我关注https://laravel.com/docs/5.3/passport#installation

Both(cli耳鼻喉科/服务器)的本地主机上的

+0

尝试注册中间件到Web中间件组,而不是一个API – Hammerbot

+0

@El_Matella,那么这两个请求失败。我做了一个'php工匠路线:列表'和那条路线只有中间件是'throttle' – Miguel

+0

如果你在全球注册它? – Hammerbot

回答

0

运行假设你正在使用VUE资源尝试从devtools调试在网络选项卡电话。

如果没有CORS标头存在于请求头选项卡,就把这行某处Vue.use(VueResource)后:Vue.http.options.crossOrigin = true