title: How can I use Perl to send and HTTP request with a cookie?
body: <p>I am new to Perl and I want to write a Perl program that:</p>
  
  <ul>
  <li>creates an HTTP request</li>
  <li>sends it to any URL (e.g. <a href="http://www.google.com" rel="noreferrer">http://www.google.com</a> )</li>
  <li>includes a cookie in the request</li>
  <li>logs the http response codes in a file</li>
  </ul>
  
  <p>I have tried this:</p>
  
  <pre><code>    #!/usr/bin/perl
  require HTTP::Request;
  require LWP::UserAgent;
  
  $request = HTTP::Request-&gt;new(GET =&gt; 'http://www.google.com/');
  $ua = LWP::UserAgent-&gt;new;
  $ua-&gt;cookie_jar({file =&gt; "testcookies.txt",autosave =&gt;1});
  
  $response = $ua-&gt;request($request);
  if($response-&gt;is_success){
  print "sucess\n";
  print $response-&gt;code;
  }
  else {
  print "fail\n";
  die $response-&gt;code;
  }
  </code></pre>
  
  <p>pls tell how to set cookie in 'request' ie </p>
  
  <p>how to set a cookie when we send HTTP::Request</p>
  
  <p>i was expecting something like:</p>
  
  <pre><code>$request = HTTP::Request-&gt;new(GET =&gt; 'http://www.google.com/');
  $ua = LWP::UserAgent-&gt;new;
  $ua-&gt;new CGI::Cookie(-name=&gt;"myCookie",-value=&gt;"fghij");
  </code></pre>
  
  <p>is this possible??</p>