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

Discussion in 'Perl' started by La Jesus, Oct 27, 2003.

  1. La Jesus

    La Jesus Guest

    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!
     
    La Jesus, Oct 27, 2003
    #1
    1. Advertising

  2. 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
     
    Gunnar Hjalmarsson, Oct 27, 2003
    #2
    1. Advertising

  3. 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
     
    Gunnar Hjalmarsson, Oct 27, 2003
    #3
  4. La Jesus

    La Jesus Guest

    >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);
     
    La Jesus, Oct 27, 2003
    #4
  5. La Jesus

    La Jesus Guest

    3) User gets redirected to Site C, as if they submitted there in STEP 1, (I
    meant.)
     
    La Jesus, Oct 27, 2003
    #5
  6. 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
     
    Gunnar Hjalmarsson, Oct 27, 2003
    #6
  7. La Jesus

    La Jesus Guest

    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" <> wrote in message
    news:AYenb.31369$...
    > 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
    >
     
    La Jesus, Oct 27, 2003
    #7
  8. 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
     
    Gunnar Hjalmarsson, Oct 27, 2003
    #8
  9. La Jesus

    Ed Green Guest

    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" <> wrote in message
    news:nKfnb.31383$...
    > 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
    >
     
    Ed Green, Oct 27, 2003
    #9
  10. 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
     
    Gunnar Hjalmarsson, Oct 27, 2003
    #10
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Rubel Kanubel

    Post radiobuttons (forms) using lwp-useragent

    Rubel Kanubel, Oct 12, 2003, in forum: Perl Misc
    Replies:
    5
    Views:
    229
    Anno Siegel
    Oct 13, 2003
  2. Paul Lemmons

    LWP::UserAgent and SSL is it impossible?

    Paul Lemmons, Nov 11, 2003, in forum: Perl Misc
    Replies:
    4
    Views:
    175
    Pierre Asselin
    Nov 12, 2003
  3. Andrew
    Replies:
    1
    Views:
    356
    Gunnar Hjalmarsson
    Dec 5, 2003
  4. dan baker
    Replies:
    0
    Views:
    112
    dan baker
    Jan 18, 2004
  5. Zapanaz
    Replies:
    4
    Views:
    134
    Tad McClellan
    Oct 12, 2005
Loading...

Share This Page