title: Symfony2 Guzzle store cookie for request
body: <p>Trying to make my Symfony2 Controller make request to backed API. Need to store the cookie received upon first API request to use it in second request.</p>
  
  <p>Here is my Controller code:</p>
  
  <pre><code>use Guzzle\Http\Client;
  
  use Guzzle\Plugin\Cookie\CookiePlugin;
  use Guzzle\Plugin\Cookie\CookieJar\ArrayCookieJar;
  
  
  class DefaultController extends Controller
  {
  
     public function verifyurlActionOK(Request $request)
     {
  
  
     $cookiePlugin = new CookiePlugin(new ArrayCookieJar());
  
     $client = new Client();
  
     $this-&gt;get('session')-&gt;set('client', $client);
  
     $client-&gt;addSubscriber($cookiePlugin);
     $request = $client-&gt;get('https://address/scanit?url='.$scantarget);
     $response = $request-&gt;send();
     }
  
     public function progressAction(Request $request)
     {
     $cli = $session-&gt;get('client');
  
     $crequest = $cli-&gt;get('https://address/progress');
     $response = $crequest-&gt;send();
  
  
     return $this-&gt;render('AppBundle:Default:progress.html.twig',
                          array(
                          'response'  =&gt; $cresponse-&gt;getBody()));
     }
  
  
  }
  </code></pre>
  
  <p>Tried to set Client as a public variable in DefaultController class and as above in a Session (serialized). Both does not seem to work, here error appear on get() in the progressAction</p>
  
  <pre><code>[2016-11-29 16:22:46] request.CRITICAL: Uncaught PHP Exception Symfony\Component\Debug\Exception\FatalErrorException: "Error: Call to a member function get() on a non-object"
  </code></pre>
  
  <p>How to access $client from verifyurlActionOK in progressAction??</p>
  
  <p>Thanks,</p>