首页 > 解决方案 > Laravel POST 方法作为 GET 方法发送。代码 405

问题描述

因此,我已经查看了与我的问题相关的答案。我有一个 laravel 应用程序,它在我的本地主机服务器上运行良好。那里的路线运行良好。但是当我在共享主机上上传我的 laravel 应用程序时,只有 GET 方法有效。当我尝试使用任何 POST 请求(例如登录到我的应用程序)时,它会发送 405 错误代码。因此,例如,当我登录时,我会告诉你什么是错误的。

这是路线。

Route::post('authinticate',['as'=>'authinticate','uses'=>'LoginController@authenticate']);

控制器功能

public function authenticate(LoginRequest $request)
    { //$credentials = $request->only('user_name', 'password');

        $credentials = array(
            'user_name' => $request->input('username'),
             'password' => $request->input('password'),
            );


        if (Auth::attempt($credentials)) {
            // Authentication passed...
            return redirect()->route('home');
        }
        else{
            return redirect()->back()->withErrors(['message' => 'اسم المستخدم او كلمة المرور غير صحيحين.']);
        }
    }

HTML 表单:

<form method="POST" action="{{ route('authinticate') }}">
                @csrf

                    <div class="form-group signIn">
                        <label for="username">اسم المستخدم</label>
                        <input type="text" name="username" placeholder="اسم المستخدم" class="form-control" id="username" value="{{ old('user_name') }}">
                    </div>
                    <div class="form-group">
                        <label for="password">كلمة المرور</label>
                        <input type="password" name="password" placeholder="كلمة المرور" class="form-control" id="password">
                        <p></p>
                        <a href="{{ route('forgot') }}" >نسيت كلمة المرور</a>
                    </div>
                    <input type="submit" class="btn btn-block btn-default btn-success" name="submit" id="submit" value="دخـــول">
                </form>

这是我在提交表单之前从控制台得到的。

Mixed Content: The page at 'https://www.aouacc.net/login' was loaded over a secure connection, but contains a form that targets an insecure endpoint 'http://www.aouacc.net/authinticate'. This endpoint should be made available over a secure connection.

这是在提交之后。 在此处输入图像描述

在此处输入图像描述

标签: phplaravelhttp-status-code-405

解决方案


检查标头,POST 请求http://www.aouacc.net/aunthinticate返回一个301 Mover Permanently标头,这会触发重定向到 https 版本。由于显然您没有在代码中设置该重定向,因此它可能已设置在服务器级别。更改您的路线,以便他们使用https://www.aouacc.net而不是http://www.aouacc.net.


推荐阅读