简体   繁体   English

Laravel “Symfony\Component\HttpKernel\Exception\HttpException”错误

[英]Laravel "Symfony\Component\HttpKernel\Exception\HttpException" error

In my Laravel, Vue JS application, I'm getting this type of error after I transferred my application to our server.在我的 Laravel,Vue JS 应用程序中,我在将应用程序传输到我们的服务器后遇到了此类错误。

Symfony\Component\HttpKernel\Exception\HttpException Symfony\Component\HttpKernel\Exception\HttpException

I saw the same problem here but there's no answer.我在这里看到了同样的问题,但没有答案。 I hope this time there will be someone that can provide an answer or solution for this type of error.我希望这次会有人可以为此类错误提供答案或解决方案。

Note:笔记:

  1. This error only happens if I tried to access the application from a server using other devices.仅当我尝试使用其他设备从服务器访问应用程序时才会发生此错误。
  2. Error occurs irregularly .错误发生不规律 If it doesn't show on first, sometimes shows-up after 2 or more ajax request.如果它没有首先显示,有时会在 2 个或更多 ajax 请求后显示。
  3. I'm using vForm for my ajax request.我正在为我的 ajax 请求使用vForm
  4. It works fine on my pc/localhost.它在我的 pc/localhost 上运行良好。
  5. It works fine as well when I tried to access my application inside my server.当我尝试访问服务器内的应用程序时,它也可以正常工作。 I mean, I tried to use the browser inside our server and it works with no problem.我的意思是,我尝试在我们的服务器中使用浏览器,它没有问题。

PS. PS。

  • I checked my Request Header and X-CSRF-TOKEN is there.我检查了我的请求 HeaderX-CSRF-TOKEN在那里。
  • In my Request Payload _token is there as well.在我的请求有效负载中, _token也在那里。

Below are my codes:以下是我的代码:

VueJS Method: VueJS 方法:

UpdateDepartmentInfo(){

            this.departmentToUpdate._token = this.$root.csrf;

            this.requestUpdateDepartmentOnProgress = true;

            this.departmentToUpdate.put('department/'+this.departmentToUpdate.id)
                .then((response) => {              
                    this.requestUpdateDepartmentOnProgress = false;      
                    this.GetDepartmentList();
                    swal(
                        'Department Info. Saved!',
                        'Department information has been successfully updated to database!',
                        'success'
                    );
                })
                .catch((error) => {
                    this.requestUpdateDepartmentOnProgress = false;
                    if (error.response.status == 401) {
                        alert('User session has expired. Please login again.');
                        location.replace("/login");
                    }
                });
        }

Laravel Controller: Laravel Controller:

public function update(Request $request, $id)
    {

        // Check if the department object from model if it exists
        try{
            $department = Department::findOrFail($id);
        }catch(\Exception $e){
            return response(['error' => 'The department you want to edit can\'t be found in the database!' ], 400);
        }

        // check if it was just the status was sent 
        if($request['newStat'] != null){
            $department->status  = $request['newStat'];
        }else{

            $this->validate($request,[
                'name'      => 'required|string|max:191',
                'code'      => 'required|string|max:10',
            ]);

            $department->name           = $request['name'];
            $department->code           = $request['code'];
            $department->description    = $request['description'];
            $department->status         = $request['status'];       
        }

        $department->save();
        return ['message' => 'ok'];


    }

Thank you in advance先感谢您

in your.env file make changes like this在 your.env 文件中进行这样的更改

APP_URL=http://your_server_url

or you have to put thin in your index.php file或者你必须在你的index.php文件中放薄

header("Access-Control-Allow-Origin: http://localhost");

check in the resources/js/components folder in you component if you have如果有,请检查组件中的 resources/js/components 文件夹
http://127.0.0.1:8000/fetchusers

change it to将其更改为

 fetch('fetchusers',{
            method:'POST',
            headers:{
                'Content-Type':'application/json',
                X_CSRF_TOKEN:('meta[name="csrf-token"]').content,
                'Accept':'application/json'
            }
        })

it might help.它可能会有所帮助。

it's because of the csrf_token usually, you can check this documentation hope it will solve yours too.这是因为 csrf_token 通常,您可以查看此文档,希望它也能解决您的问题。

https://laravel.com/docs/5.6/csrf#csrf-x-csrf-token https://laravel.com/docs/5.6/csrf#csrf-x-csrf-token

To do: <meta name="csrf-token" content="{{ csrf_token() }}">待办事项: <meta name="csrf-token" content="{{ csrf_token() }}">

    headers: {
        'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
    }
});```
 

check your storage/log/laravel.log file is there.检查您的storage/log/laravel.log文件是否存在。 Also they have permission to write/read他们也有写/读的权限

this can be fixed quite easily by running:这可以通过运行很容易地解决:

sudo chmod -R 777 storage/logs

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Laravel 5.4中的Symfony \\ Component \\ HttpKernel \\ Exception \\ HttpException错误 - Symfony\Component\HttpKernel\Exception\HttpException Error in Laravel 5.4 Laravel 4错误Symfony \\组件\\ HttpKernel \\异常\\ NotFoundHttpException - Laravel 4 Error Symfony \ Component \ HttpKernel \ Exception \ NotFoundHttpException Laravel错误Symfony \\ Component \\ HttpKernel \\ Exception \\ NotFoundHttpException - Laravel error Symfony \ Component \ HttpKernel \ Exception \ NotFoundHttpException Laravel中的Symfony \\ Component \\ HttpKernel \\ Exception \\ NotFoundHttpException错误 - Symfony \ Component \ HttpKernel \ Exception \ NotFoundHttpException Error in Laravel Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException laravel 8 错误 - Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException laravel 8 error Laravel 错误 8 Symfony\Component\HttpKernel\Exception\NotFoundHttpException - Laravel error 8 Symfony\Component\HttpKernel\Exception\NotFoundHttpException CSRF 令牌不匹配。”,异常:“Symfony\Component\HttpKernel\Exception\HttpException - CSRF token mismatch.", exception: "Symfony\Component\HttpKernel\Exception\HttpException 我在路由上使用post方法时出现Symfony \\ Component \\ HttpKernel \\ Exception \\ HttpException错误 - Symfony\Component\HttpKernel\Exception\HttpException error when I have post method on route Laravel-更新内容错误Symfony \\组件\\ HttpKernel \\异常\\ MethodNotAllowedHttpException - Laravel - Update Content Error Symfony \ Component \ HttpKernel \ Exception \ MethodNotAllowedHttpException Laravel 5.7错误消息“ Symfony \\组件\\ HttpKernel \\异常\\ MethodNotAllowedHttpException没有消息” - Laravel 5.7 Error message “ Symfony \ Component \ HttpKernel \ Exception \ MethodNotAllowedHttpException No message”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM