我正在使用 Laravel 5.2。我在制作android的webservice时遇到这个错误 我只做了一个登录网络服务,但它在 postman 上显示错误 VerifyCsrfToken.php 第 67 行中的 TokenMismatchException: 我知道如何在网页中处理传递 csrf_token 的隐藏字段,但我不知道如何在网络服务中处理任何人都可以帮助我 这是我的代码:-
enter code here
public function user_login(Request $request){
if($request->isMethod('post')){
$userdata = $request->all();
echo 'cvdasvc';
unset($userdata['_token']);
$checkUserExist = User::where(['mobile'=>$userdata['mobile'],'password'=>$userdata['password']])->first();
if(!empty($checkUserExist)){
$message = "Login Successfully!";
$userdata = $checkUserExist;
}else{
$message = "wrong Creditanls!";
$userdata = array();
}
echo json_encode(array(
'message' =>$message,
'data'=> $userdata
)
); die;
}
}
最佳答案
对于 Laravel 5.4,默认情况下对 API 路由禁用 CSRF 保护。 (为此,所有 API 路由都应位于 paths/api.php 内)
但是由于你使用的是 Laravel 5.2,它没有这个功能,你可以这样做:
使用“api”等标识符作为所有 Web 服务路由的前缀:
路由.php:
Route::post('api/test1', function() {
return 'test1';
});
Route::post('api/test2', function() {
return 'test2';
});
然后将其添加到 app/Http/Middleware/VerifyCsrfToken.php 中:
protected $except = [
'api/*'
];
关于php - token 不匹配异常android webservices?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42241923/