samedi 31 octobre 2015

Why does Laravel create a new session after a GuzzleHttp POST request to the same subdomain?

I'm trying to make a post request to the same subdomain with GuzzleHttp in a Laravel 5.1 installation, but as a response the login page is returned, showing that a new Session has been created in the request. The current session is not affected.

Why does Laravel create a new session?

In session.php I have the following values:

'driver' => env('SESSION_DRIVER', 'file'),
'lifetime' => 120,
'expire_on_close' => true,
'files' => storage_path('framework/sessions'),
'cookie' => 'admin_mydomain_com_session',
'path' => '/',
'domain' => 'admin.mydomain.com',
'secure' => false

In my controller I use the following code to make the request:

// Create headers
$headers = array(
    'X-CSRF-Token' => csrf_token()
);

// Create data
$data = array(
    'param' => 'param',
    '_token' => csrf_token()
);

// Create a POST request
$client = new Client();
$res = $client->request('POST', 'http://ift.tt/1WncRvO',
    array(
        'headers' => $headers,
        'form_params' => $data
    )
);
$statusCode = $res->getStatusCode();
$body = $res->getBody();

echo $body; // Shows me the login page



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire