Gibt es einen Grund, warum die Konfiguration der Cors-Richtlinien vor dem Erstellen in der Laravel 7-Anwendung nicht funktioniert?

Aug 15 2020

Ich habe eine "Post" -Anfrage mit Axios an die Laravel-Backend-Anwendung gestellt. Es wirft immer diese Fehler

nach dem Absenden des Formulars:

Access to XMLHttpRequest at 'mydomain' (redirected from 'mydomain') from origin 'mydomain' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.

vor dem Absenden des Formulars:

Cross-Origin Read Blocking (CORB) blocked cross-origin response mydomain with MIME type text/html. See https://www.chromestatus.com/feature/5629709824032768 for more details.

was ich bisher gemacht habe:

cors.php (Konfigurationsdatei in Laravel)

return [
    'paths' => ['api/*','web/*'],

    'allowed_methods' => ['*'],

    'allowed_origins' => ['*'],

    'allowed_origins_patterns' => [],

    'allowed_headers' => ['*'],

    'exposed_headers' => [
          'Cache-Control',
    'Content-Language',
    'Content-Type',
    'Expires',
    'Last-Modified',
    'Pragma', 
  ],

    'max_age' => 0,

    'supports_credentials' => false,

];

Herkunft zulassen und die Pfade wurden geändert.

vue js axios Anfrage

const result = await this.callApi('post','/user/login', this.data)

callApi-Methode

async callApi(method,url,data){

            try {
                
                //axios.defaults.headers.post['Content-Type'] ='application/x-www-form-urlencoded';
                
                 // Send a POST request
                  return await axios({
                        method: method,
                        url: url,
                        data: data
                    });
            } catch (e) {
                return e.response
            }
        }, 

Antworten

aseladaskon Aug 19 2020 at 09:48

Danke für alle Zuschauer. Der Befehl "composer update" hat das Problem behoben.