need some visual clarity/implimentation LWP help

B

buildmorelines

I would like to know how to merge the cookies line into creation of
request variable/object?. The code works fine, but for visual clarity
it would be nice to merge the cookies line into some other line if
possible.(I love Perl because it still has a good old thing called
procedural programing, OO stuff is chinese to me).

my $ua = new LWP::UserAgent;
my $request = HTTP::Request->new('GET', $my_url);
$request->header('Cookie' => 'foo_likes_it=hi');
my $response = $ua->request($request);
print $response->content;

Also, less importantly (remember TMTOWTDI), did I do the right thing
by adding a static cookies header to the HTTP request? or should the
professional way be through the cookie_jar of LWP::UserAgent, and then
to HTTP::Cookies, or play with HTTP::Headers?

The cookie is always static, and never needs to be changed. There is
no need to "save" or "capture" any cookies from the server.
 
T

Tad McClellan

buildmorelines said:
The code works fine, but for visual clarity
it would be nice to merge the cookies line into some other line if
possible.


One way to do that would be to remove the newline character
between the two lines in question. :)
 
B

Ben Morrow

Quoth (e-mail address removed) (buildmorelines):
I would like to know how to merge the cookies line into creation of
request variable/object?. The code works fine, but for visual clarity
it would be nice to merge the cookies line into some other line if
possible.(I love Perl because it still has a good old thing called
procedural programing, OO stuff is chinese to me).

my $ua = new LWP::UserAgent;
my $request = HTTP::Request->new('GET', $my_url);
$request->header('Cookie' => 'foo_likes_it=hi');
my $response = $ua->request($request);
print $response->content;

Uuuuuh....

(my $req = H:R->new())->header();
Also, less importantly (remember TMTOWTDI), did I do the right thing
by adding a static cookies header to the HTTP request? or should the
professional way be through the cookie_jar of LWP::UserAgent, and then
to HTTP::Cookies, or play with HTTP::Headers?

I would *never* write a cookies header by hand. I would use
HTTP::Cookies->set_cookie and HTTP::Cookies->add_cookie_header.

[I would also attempt to learn how to type 'cookie' without it coming
out as 'cooiek' ;) ]

Ben
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top