Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
I have taken the advice of many wise perlmonks and modified my original troublesome script (see my post). I now get a new error that I can't seem to overcome. The error is:

Can't locate object method "url" via package "HTTP::Headers" (perhaps you forgot to load "HTTP::Headers"?) at (eval 43) line 1.

So now I figure there is a problem, but can't seem to locate it. Do I have the variables and add_cookie_header/extract_cookie methods right? See my new and improved (hopefully) code below. THANKS!!

#!/usr/lib/perl use LWP::UserAgent; use HTTP::Cookies; use HTTP::Request::Common; use HTTP::Headers; #is this where I declare cookie_jar?? seems like I am doing it twice my $cookie_jar = HTTP::Cookies->new; my $ua = LWP::UserAgent->new; #but it seems like I am nearly doing the same thing here #but I need the variable below for add_cookie_header and extract_cooki +es $ua->cookie_jar(HTTP::Cookies->new(file => 'cookie_jar', autosave =>1) +); my $request = $ua->simple_request(POST "http://www.sitedomain.com/logi +n.cfm", { username =>'abcuser', userpass =>'abc123', submit =>'Submit' }); while ($request->is_redirect) { my $u = $request->header('location') or die "missing location: ", $request->as_string; #print "redirecting to $u\n"; $u=~s/^\.+/http\:\/\/www\.sitedomain\.com/s; $request = $ua->simple_request(GET $u); } #do this before extract? is that the right variable to do it on? #HTTP::Cookies says that add_cookie_header must have a "valid url attr +ibute". #that lingo doesn't click with me $cookie_jar->add_cookie_header($request); my $response = $ua->request($request); $cookie_jar->extract_cookies($response); $ua->cookie_jar($cookie_jar); my $request = $ua->simple_request(POST "http://www.sitedomain.com/page +.cfm", { firstname =>"Michael", lastname =>"Jensen", company =>"companyname", address =>"111 East 222 South", city =>"Provo", state =>"UT", zip =>"99999" }); if ($request->is_success) { $a = "worked"; } else{ $a = "failed"; } print "$a";


Michael Jensen
InShift Technologies
http://www.inshift.com
michael@inshift.com

In reply to LWP, extract_cookies, etc. by inblosam

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 contemplating the Monastery: (7)
As of 2024-04-16 10:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found