Hi,
I have been struggling with this problem for two days. I wanna hit my head against the wall.
I have an API built with Lumen, and a web-client for the application built with Laravel. the web-client uses guzzle to send requests to the API (Lumen).
on the local environment, everything is ok. when I uploaded the Laravel and Lumen on Host, the problem arose out of nowhere.
THE PROBLEM:
when the web-client (Laravel) sends a request to Lumen, a "419 Page Expired" page turns back as result. BUT when I use CURL to send a request to Lumen, it turns back a successful response.
Guzzle:
private const BASE_URI = 'http://example.com/api';
public static function sendRequest($method, $uri = '', array $options = [])
{
$client = new Client([
'base_uri' => self::BASE_URI,
'headers' => [
'Authorization' => "Bearer {session('api_token')}",
]
]);
try {
$response = $client->request($method, $uri, $options);
} catch (RequestException $exception) {
$response = $exception->getResponse();
}
$responseContent = $response->getBody()->getContents();
dd($responseContent);
$result = json_decode($responseContent);
return self::check($result);
}
CURL:
protected static function sendPost($phoneNumber, $password)
{
$url = self::BASE_URI . '/login';
$fields = array
(
'phone_number' => $phoneNumber,
'password' => $password
);
$handler = curl_init($url);
curl_setopt($handler, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($handler, CURLOPT_POSTFIELDS, $fields);
curl_setopt($handler, CURLOPT_RETURNTRANSFER, true);
$responseContent = curl_exec($handler);
dd($responseContent);
$result = json_decode($responseContent);
return self::check($result);
}
a portion of the response:
<title>Page Expired</title>
<!-- Fonts -->
<link rel="dns-prefetch" href="//fonts.gstatic.com">
<link href="https://fonts.googleapis.com/css?family=Nunito" rel="stylesheet">
<!-- Styles -->
<style>
html, body {
background-color: #fff;
color: #636b6f;
font-family: 'Nunito', sans-serif;
font-weight: 100;
height: 100vh;
margin: 0;
}
.full-height {
height: 100vh;
}
.flex-center {
align-items: center;
display: flex;
justify-content: center;
}