我几天来一直试图解决这个问题。每当我运行代码时,我都会得到此响应"响应状态:控制台中的URL为500内部服务器错误。
当我查看网络表时,它在VerifyCsrfToken.php第68行"中显示" TokenMismatchException;我在网上尝试了很多解决方案,但问题仍然存在。
<?php
use Illuminate\Http\Request;
/*
|--------------------------------------------------------------------------
| API Routes
|--------------------------------------------------------------------------
|
| Here is where you can register API routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| is assigned the "api" middleware group. Enjoy building your API!
|
*/
/*Route::get('/user', function (Request $request) {
* return $request->user();
* })->middleware('auth:api');
*/
//Cors
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: POST, GET, OPTIONS, PUT, DELETE ');
header('Access-Control-Allow-Headers: Content-Type, X-Auth-Token, Origin, Authorization, x-xsrf-token, x-csrf-token, Accept');
Route::group(['prefix' => 'api/v1', 'middleware' => 'cors',], function(){
# Handling customers issues...
Route::get('/customers', 'CountryController@index');
});
<?php
namespace App\Http\Middleware;
use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken as BaseVerifier;
class VerifyCsrfToken extends BaseVerifier
{
/**
* The URIs that should be excluded from CSRF verification.
*
* @var array
*/
protected $except = [
'/agents/'
];
}