CORS未通过邮寄请求

时间:2017-01-05 12:38:35

标签: cors vue.js laravel-5.3

我有这件Vue.js:

...
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)
})
...

最后一次获取请求正常,但该帖子由于

而没有通过
  

XMLHttpRequest无法加载http://localhost:8000/oauth/token。对预检请求的响应没有通过访问控制检查:否'访问控制 - 允许 - 来源'标头出现在请求的资源上。起源......

我的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,默认情况下它是唯一一个...我跟随app.get("/delete", function(req, res) { req.session.destroy(); res.end(); }); {3}}

两者(客户端/服务器)都在localhost上运行

1 个答案:

答案 0 :(得分:0)

假设您正在使用 vue-resource 尝试在 devtools 的网络标签中调试您的电话。

如果请求标题标签中没有CORS标题,请将此行放在Vue.use(VueResource)之后的某个位置:Vue.http.options.crossOrigin = true

相关问题