Thomas Crawford
Thomas Crawford

Reputation: 896

Send cookie with cookieJar in Guzzle POST request not working

I am trying to send a cookie with my request to an rest api server. This cookie is needed to make requests to the API server.

But the cookie is never send. Any ideas why this is?

   $cookieJar = CookieJar::fromArray([
      'cookie_name' => 'cookie_value',
    ], '/');

    $token = 'sfsdfkdsfksdf';

      $body = [
        'headers' => [
          'Accept' => 'application/json',
          'Content-type' => 'application/json',
          'X-sess-id' => $token,
        ],
        'cookies' => $cookieJar,
      ];


      $request = $this->httpClient->request('POST', 'https://myendpoint.com', $body);

      var_dump($request); exit;

I am using guzzle version 6.3.2

enter image description here

The request body.

Upvotes: 1

Views: 1226

Answers (1)

Thomas Crawford
Thomas Crawford

Reputation: 896

It turns out that i needed to set the domain cookie and not only '/'

Upvotes: 1

Related Questions