mkabbanii
mkabbanii

Reputation: 69

Laravel POST method being sent as GET method. Code 405

So I already looked at the answers that are related to my issue. I have a laravel application which is working great on my localhost server. Routes are working fine there. But when I uploaded my laravel application on shared hosting, only GET methods are working. When I try to use any POST request such as login to my application, it sends 405 error code. So i'll show you what is wrong when I login for example.

This is the route.

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

The controller function

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:

<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>

This is what I get from console before submitting the 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.

And this is after submitting. enter image description here

enter image description here

Upvotes: 0

Views: 2228

Answers (1)

Jos&#233; A. Zapata
Jos&#233; A. Zapata

Reputation: 1307

Check the headers, the POST request to http://www.aouacc.net/aunthinticate returns a 301 Mover Permanently header, which triggers a redirect to the https version. Since apparently you're not setting that redirect in your code, it might have been set at a sever level. Change your routes so they use https://www.aouacc.net instead of http://www.aouacc.net.

Upvotes: 3

Related Questions