Access-Control-Allow-Origin (Laravel & Vue) CORS CORB error on localhost

前端 未结 2 921
有刺的猬
有刺的猬 2021-01-16 13:28

I use this package and it didn\'t work (https://github.com/barryvdh/laravel-cors)

addSMS() {
    axios.post(\'https://smsmisr.com/api/webapi\', {
           


        
相关标签:
2条回答
  • 2021-01-16 13:57

    As you have no access in API's source code so there is nothing to do with .htaccess or adding 'Access-Control-Allow-Origin': '*', in script. But still you can eradicate this error by opening chrome browser with disabled security mode

    In windows run CMD (press together windows button and R key from keyboard. Then type cmd in box and enter).

    Secondly go to C drive (in CLI) or where your chrome installed (using cd command) then run following command

    “Program Files (x86)\Google\Chrome\Application\chrome.exe” –-allow-file-access-from-files --disable-web-security --user-data-dir --disable-features=CrossSiteDocumentBlockingIfIsolating
    

    It will open your browser in disabled web security mode. Once you done it you can test now with this kind of CORS or CORB error.

    note: before running this command make sure there are no chrome are opened already.

    Program Files (x86)\Google\Chrome\Application\chrome.exe this should be your chrome installed path

    However after opening browser it will show as below, dont panic & dont close this message. if you close this message it will again through this CORS or CORB error

    0 讨论(0)
  • 2021-01-16 14:10

    Update config/cors.php

       'supportsCredentials' => false,
       'allowedOrigins' => ['*'],
       'allowedHeaders' => ['*'],
       'allowedMethods' => ['*'], // ex: ['GET', 'POST', 'PUT',  'DELETE']
       'exposedHeaders' => ['*'],
       'maxAge' => 0,
    
       then run
       php artisan config:cache 
       command i think it will help you
    
    0 讨论(0)
提交回复
热议问题