Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"

Send a String to another URL

by virtualweb (Sexton)
on May 12, 2011 at 01:19 UTC ( #904276=perlquestion: print w/ replies, xml ) Need Help??
virtualweb has asked for the wisdom of the Perl Monks concerning the following question:

Hi... I have a Form submitting data to a form processing script which shows the results in the browser.

Now I want to send some of the data from this form handler to another script in another URL.

Sinse I have the (print "Content-type: text/html\n\n";) Header up at top in my script


#!/usr/bin/perl print "Content-type: text/html\n\n"; use CGI qw(:standard); use CGI::Carp (fatalsToBrowser); $query = new CGI;

when I use "Location" as in the example below:

my $url = " +ey2=value2&key3=value3"; print "Location: $url\n\n";

it doesnt work

what line of code should i use..??

Thank you

Comment on Send a String to another URL
Select or Download Code
Re: Send a String to another URL
by thewebsi (Beadle) on May 12, 2011 at 03:52 UTC

    1. In HTTP, the headers and content are separated by an empty line. The "Location:" bit is supposed to go in the header, but because you have a "\n\n" printed out before it, it ends up in the content, and doesn't have the desired effect. I think you already figured this part out.

    2. To show something on the browser AND send data to another URL is not something usually done with a redirect. For a server-side solution using Perl, look into instead (lots of documentation and examples if you look around).

    3. Another option is AJAX, which is done through Javascript (not Perl). Some find this simpler, but it does rely on client-side technology, which has its drawbacks.

      Thank you for you prompt response .

      My script is processing a purchase order from a shopping cart. I want to give the seller a sales notification via SMS, so I signed up with one of those Bulk API services.

      They gave me a URL where to send the parameters for a text message as follows:

      http://SERVERIP/httppush/http.aspx?text=TEXTMESSAGE&source=SOURCENUMBER&desti nation=DESTINATIONNUMBER&username=USERNAME&password=PASSWORD&datacodi ng=1

      I need to replace all the Capitalized words with the pertinent information: The sender's number, the recipient's number, etc.

      If I cannot place the "Location" bit below the extra line caused by "\n\n" , is there a system call that can be used in this case..?? someone suggested: system("wget") but I dont have the complete construct of this line.

Re: Send a String to another URL
by tospo (Hermit) on May 12, 2011 at 08:30 UTC
    Why don't you make that form-processing script send a request to this other URL and process the response fomr that one? Why do you explicitly print a header in your script and not use the 'header' method?

      Hello Tospo.. thanx for your suggestions

      I taught myself perl through books and tutorials so I have many lagoons and holes in my knowledge... example, I never heard of the 'header' , I dont know how it is used and what the syntax is.

      Perhaps you could show me and then I could try.

      Thanx again

        ah, ok. In that case you should start with the CGI docs here. As you can see, you print the header like this:
        use CGI; my $q = CGI->new; print $q->header(); ### generate and print more stuff for the web page here
        As suggested previously, you can use LWP::Simple to send your stuff and capture the response from the remote server, which might tell you if the message has been sent successfully if that service is well implemented. If you do get a "receipt" then it will probably be in XML format and you will then want to use a module that helps you with parsing the XML, something like XML::Simple (there are many options).

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://904276]
Approved by Corion
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (7)
As of 2014-07-12 05:15 GMT
Find Nodes?
    Voting Booth?

    When choosing user names for websites, I prefer to use:

    Results (238 votes), past polls