Laravel Access to XMLHttpRequest at from origin has been blocked by CORS policy

﹥>﹥吖頭↗ 提交于 2019-12-04 07:38:34

问题


When I Send a Call from Angular Application to Laravel I am getting the below issue

Access to XMLHttpRequest at 'http://localhost:8083/api/login_otp' from origin 'http://localhost:4200' has been blocked by CORS policy: Request header field ip is not allowed by Access-Control-Allow-Headers in preflight response.

i found a solution and did the below changes

in CROS.php

public function handle($request, Closure $next)
    {
        return $next($request)
        ->header('Access-Control-Allow-Origin', '*') 
        ->header('Access-Control-Allow-Methods', 'GET, POST, PATCH, PUT, DELETE, OPTIONS')
        ->header('Access-Control-Allow-Headers', 'Origin, Content-Type, X-Auth-Token, Authorization, X-Requested-With, x-xsrf-token');
    }

i Added x-xsrf-token in Access-Control-Allow-Headers still i am getting the same issue


回答1:


Read the error message:

Request header field ip is not allowed by Access-Control-Allow-Headers

It says ip is not allowed.

Look at your code:

'Origin, Content-Type, X-Auth-Token, Authorization, X-Requested-With, x-xsrf-token'

Your code doesn't mention ip.

Add ip to the list of allowed headers.



来源:https://stackoverflow.com/questions/55414508/laravel-access-to-xmlhttprequest-at-from-origin-has-been-blocked-by-cors-policy

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!