I am trying to login in to a site and then post to a page while still logged in. I can log in fine, but as soon as I try to do the second post I am stuck with an HTTP 1.1/302 error as follows:
HTTP/1.1 302 (Found) Object Moved Connection: close Location: defaultpage.cfm?sid=99999999999&CFID=99999&CFTOKEN=9999999 Server: Microsoft-IIS/5.0 Content-Length: 196 Content-Type: text/html Client-Date: Tue, 21 May 2002 06:50:00 GMT Client-Response-Num: 1 Title: Document Moved
Object Moved
This document may be found here
If anyone has any suggestions, maybe even another way to do it, please share. Thanks! My code is as follows (with login/site info taken out):
#!usr/bin/perl -w
use LWP::UserAgent;
use HTTP::Cookies;
use HTTP::Request::Common;
my $ua = LWP::UserAgent->new;
$ua->cookie_jar(HTTP::Cookies->new(file => 'cookie_jar', autosave =>1)
+);
my $r = $ua->simple_request(POST "http://www.sitedomain.com/login.cfm"
+,
{
username =>'abcuser',
userpass =>'abc123',
submit =>'Submit'
});
while ($r->is_redirect) {
my $u = $r->header('location') or die "missing location: ",
$r->as_string;
#print "redirecting to $u\n";
$u=~s/^\.+/http\:\/\/www\.sitedomain\.com/s;
$r = $ua->simple_request(GET $u);
}
my $r = $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"
});
$b = $r->as_string;
if ($r->is_success) {
$a = "worked";
}
else{
$a = "failed";
}
print "b is $b";
Michael Jensen
InBlosam Productions
http://www.inblosam.com
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.