LWP::UserAgent to POST and redirect browser at the same time

L

La Jesus

Hello - I am new to Perl, so sorry if this is a silly / ultra easy
question.

I am using LWP::UserAgent to POST a HTTP message to another website, and it
works great.

However, I can't figure out how to redirect the user to a script at the same
time as the post. (i.e. emulate sumbitting a form and being sent to a page.

$org_response = $res->as_string; this gives me the page as a string, but
I want to send the user there

http://www.perldoc.com/perl5.6/lib/LWP/UserAgent.html does not help
:-(

Thanks!
 
G

Gunnar Hjalmarsson

La said:
I can't figure out how to redirect the user to a script at the same
time as the post. (i.e. emulate sumbitting a form and being sent
to a page.

$org_response = $res->as_string; this gives me the page as a
string, but I want to send the user there

print "Location: $org_response\n\n";
 
G

Gunnar Hjalmarsson

Gunnar said:
print "Location: $org_response\n\n";

Sorry, I was too quick with clicking the send button. To redirect to a
certain URL, and provided that the URL is in e.g. the variable $url,
you can do:

print "Location $url\n\n";
 
L

La Jesus

print "Location $url\n\n";

What I want to do is POST $url a group of vars, and redirect the user to the
site where the POST went. So it will be "as if" the user filled out a form
on a webpage, and got redirected to the site. I think (?) that if I "print
"Location ..." then it won't be linked to the POST message.

1) User hits submit on Site A
2) Form gets sent to CGI in Site B
3) User gets redirected to Site C, as if they submitted there in Site 1

THANKS for your time!

--
while ( ($key, $value) = each(%aec) ) {$aec_post=$aec_post."$key=$value\&";}
$ua = LWP::UserAgent->new;
my $req = HTTP::Request->new(POST => $url);
$req->content_type('application/x-www-form-urlencoded');
$req->content($aec_post);
my $res = $ua->request($req);
 
L

La Jesus

3) User gets redirected to Site C, as if they submitted there in STEP 1, (I
meant.)
 
G

Gunnar Hjalmarsson

La said:
What I want to do is POST $url a group of vars, and redirect the
user to the site where the POST went. So it will be "as if" the
user filled out a form on a webpage, and got redirected to the
site. I think (?) that if I "print "Location ..." then it won't
be linked to the POST message.

1) User hits submit on Site A
2) Form gets sent to CGI in Site B
3) User gets redirected to Site C, as if they submitted there in
step 1

What's the reason why you don't submit the data via a form instead of
using LWP::UserAgent?
 
L

La Jesus

I am making a "middleware" system for a shopping cart. I take what-ever the
shopping cart sends, remap variable names, add some others, and send it to
the payment processors. This is instead of changing everything in the
cart - it's much easier.

So, the shopping cart sends to my script, I do some changes, and send it the
payment processor. However, the user must log into their account, like
PayPal. So, I need to "post" and send the user there
 
G

Gunnar Hjalmarsson

La said:
I am making a "middleware" system for a shopping cart. I take
what-ever the shopping cart sends, remap variable names, add some
others, and send it to the payment processors. This is instead of
changing everything in the cart - it's much easier.

So, the shopping cart sends to my script, I do some changes, and
send it the payment processor. However, the user must log into
their account, like PayPal. So, I need to "post" and send the user
there

Okay, I think I get the picture, but I have to admit that I'm not able
to provide a solution. In some way, if possible, you want the HTTP
response to go to the browser instead of the script from which the
request was actually sent...

If you didn't know it, this newsgroup is defunct, and it's basically
not a good idea to ask questions here. I believe that the most
appropriate Usenet group for your problem is

comp.infosystems.www.authoring.cgi (ciwac)

For more general Perl problems (i.e. not this particular problem) you
should better use

comp.lang.perl.misc

in the future.

I would recommend that you ask for help at ciwac. If you haven't
posted there before, don't forget to approve your post:
http://www.thinkspot.net/ciwac/howtopost.html

Good luck!
 
E

Ed Green

Thanks! I posted it there. I tried to approve it, but I get "sender not
found". I followed all the directions. However, I see it there (from
edgreen - a temp e-mail I used to avoid spam) Do you see it as well?
 
G

Gunnar Hjalmarsson

Ed said:
Thanks! I posted it there. I tried to approve it, but I get
"sender not found". I followed all the directions. However, I see
it there (from edgreen - a temp e-mail I used to avoid spam) Do
you see it as well?

No, at least it has not yet reached the newsgroup server that I'm
using for ciwac. Note that you need to approve the article from the
same address as the article was posted.

Another general Usenet advise: Don't top post when replying!
http://web.presby.edu/~nnqadmin/nnq/nquote.html

Following those advises will increase your chances to get your
questions answered.
 

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

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top