Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

This is how we do it with an OO LWP wrapper we use, hope it helps:

sub new { my $class = shift; my %args = @_; my $self = { _ua => LWP::Custom->new() }; bless $self, $class; # check for passed args to modify defaults $self->{cookie_dir} = $args{cookie_dir} ? $args{cookie_dir} : '/tm +p'; # pretend to be IE6 by default ;-) $self->{agent} = $args{agent} ? $args{agent} : 'Mozilla/4.0 (compa +tible; MSIE 6.0; Windows NT 5.0; .NET CLR 1.0.3705)'; # use a 30 secont timout by default $self->{timeout} = $args{timeout} ? $args{timeout} : 30; # meta refresh threshold $self->{meta_threshold} = $args{meta_threshold} ? $args{meta_thres +hold} : 15; # support cookies, first make a unique cookie file for this instan +ce my ( $fh, $name ) = get_tempfile ( $self->{cookie_dir}, 'cookie' ) +; # as we have created the file we need to make it look like a cooki +e file # so that LWP does not winge about the missing header print $fh "#LWP-Cookies-1.0\n"; close $fh; $self->{cookie_file} = "$self->{cookie_dir}/$name"; # set up the cookie jar $self->{_cookie_jar} = HTTP::Cookies->new( file => $self->{cookie_fil +e}, autosave => 0, ignore_discard => 1 ); $self->{_cookie_jar}->load( $self->{cookie_file} ); $self->{_ua}->agent( $self->{agent} ); $self->{_ua}->timeout( $self->{timeout} ); return $self; } # this is the simplified guts of the fetch method: my $request = HTTP::Request->new( $method, $url ); # this call can choke, an example is shopping.aol.co.uk which meta + # refreshes to aol://1722:ukshopping causing this call to explode eval{$self->{_cookie_jar}->add_cookie_header($request)}; my $response = $self->{_ua}->request($request); $self->{_cookie_jar}->extract_cookies($response); $self->{_cookie_jar}->save( $self->{cookie_file} ); $obj->{content} = $response->content; $obj->{code} = $response->code; $obj->{message} = $response->message; $obj->{title} = $response->headers->title; # we customize the LWP::UserAgent class to suit our needs package LWP::Custom; use base 'LWP::UserAgent'; # add a set_basic_credentials method, using a closure to remember { my ( $username, $password ); sub set_basic_credentials{ ( $username, $password ) = @_[1..2] } sub get_basic_credentials{ $username, $password }; }

cheers

tachyon

s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print


In reply to Re: Getting a Cookie from .net iis server by tachyon
in thread Getting a Cookie from .net iis server by benny666

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (2)
As of 2024-04-19 18:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found