Very helpful, but now I have that crazy HTTP 302 error. I had to add use HTTP::Cookies; into the script again because it didn't like not having it.
Any ideas why I get the error and/or how do I get around it? Also, Ilya you had simple_request on the second post. Did you mean to have just 'request' there? And do I not need "my $request = " on the first "$ua->request(POST..." line? Or the "$ua->cookie_jar" line?
What I am trying to accomplish is to update my user information on a website that requires a login. So first I need to login and then use the cookie info for posting my user information on a different form. THANKS!
#!/usr/lib/perl -w
use strict;
use LWP::UserAgent;
use HTTP::Request::Common;
# didn't work without this use statement
use HTTP::Cookies;
my $ua = LWP::UserAgent->new;
$ua->cookie_jar(HTTP::Cookies->new(file => 'cookie_jar', autosave =>1)
+);
$ua->request(POST "http://www.sitedomain.com/login.cfm",
{
username =>'abcuser',
userpass =>'abc123',
submit =>'Submit'
});
my $request = $ua->request(POST "http://www.sitedomain.com/editinfopag
+e.cfm",
{
firstname =>"MyName",
lastname =>"MyLastName",
company =>"companyname",
address =>"111 East 222 South",
city =>"Provo",
state =>"UT",
zip =>"99999"
});
print $request->is_success ? "worked\n" : "failed\n";
# this shows me that I have the following error:
# HTTP/1.1 302 (Found) Object Moved...
print $request->as_string;
-
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.