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

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • La Jesus

    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!


  • Gunnar Hjalmarsson

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

    La Jesus wrote:[color=blue]
    > 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[/color]

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

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

    Comment

    • Gunnar Hjalmarsson

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

      Gunnar Hjalmarsson wrote:[color=blue]
      > La Jesus wrote:[color=green]
      >> 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[/color]
      >
      > print "Location: $org_response\n \n";[/color]

      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

      Comment

      • La Jesus

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

        >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=$va lue\&";}
        $ua = LWP::UserAgent->new;
        my $req = HTTP::Request->new(POST => $url);
        $req->content_type(' application/x-www-form-urlencoded');
        $req->content($aec_p ost);
        my $res = $ua->request($req );


        Comment

        • La Jesus

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

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




          Comment

          • Gunnar Hjalmarsson

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

            La Jesus wrote:[color=blue][color=green]
            >> print "Location $url\n\n";[/color]
            >
            > 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[/color]

            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

            Comment

            • La Jesus

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

              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" <noreply@gunnar .cc> wrote in message
              news:AYenb.3136 9$mU6.85657@new sb.telia.net...[color=blue]
              > La Jesus wrote:[color=green][color=darkred]
              > >> print "Location $url\n\n";[/color]
              > >
              > > 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[/color]
              >
              > 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
              >[/color]


              Comment

              • Gunnar Hjalmarsson

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

                La Jesus wrote:[color=blue]
                > Gunnar Hjalmarsson wrote:[color=green]
                >> What's the reason why you don't submit the data via a form
                >> instead of using LWP::UserAgent?[/color]
                >
                > 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[/color]

                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.infosystem s.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:


                Good luck!

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

                Comment

                • Ed Green

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

                  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" <noreply@gunnar .cc> wrote in message
                  news:nKfnb.3138 3$mU6.85742@new sb.telia.net...[color=blue]
                  > La Jesus wrote:[color=green]
                  > > Gunnar Hjalmarsson wrote:[color=darkred]
                  > >> What's the reason why you don't submit the data via a form
                  > >> instead of using LWP::UserAgent?[/color]
                  > >
                  > > 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[/color]
                  >
                  > 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.infosystem s.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
                  >[/color]


                  Comment

                  • Gunnar Hjalmarsson

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

                    Ed Green wrote:[color=blue]
                    > 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?[/color]

                    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!


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

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

                    Comment

                    Working...