468,505 Members | 1,707 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,505 developers. It's quick & easy.

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

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!
Jul 19 '05 #1
9 11591
La Jesus wrote:
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";

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl

Jul 19 '05 #2
Gunnar Hjalmarsson wrote:
La Jesus wrote:
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";


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";

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl

Jul 19 '05 #3
>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);
Jul 19 '05 #4
3) User gets redirected to Site C, as if they submitted there in STEP 1, (I
meant.)


Jul 19 '05 #5
La Jesus wrote:
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
step 1


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

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl

Jul 19 '05 #6
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
"Gunnar Hjalmarsson" <no*****@gunnar.cc> wrote in message
news:AY*******************@newsb.telia.net...
La Jesus wrote:
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
step 1


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

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl

Jul 19 '05 #7
La Jesus wrote:
Gunnar Hjalmarsson wrote:
What's the reason why you don't submit the data via a form
instead of using LWP::UserAgent?


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!

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl

Jul 19 '05 #8
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?
"Gunnar Hjalmarsson" <no*****@gunnar.cc> wrote in message
news:nK*******************@newsb.telia.net...
La Jesus wrote:
Gunnar Hjalmarsson wrote:
What's the reason why you don't submit the data via a form
instead of using LWP::UserAgent?


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!

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl

Jul 19 '05 #9
Ed Green wrote:
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.

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl

Jul 19 '05 #10

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Chandra | last post: by
reply views Thread by Playker | last post: by
reply views Thread by sharif | last post: by
2 posts views Thread by haimk63 | last post: by
reply views Thread by NPC403 | last post: by
3 posts views Thread by gieforce | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.