By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,252 Members | 1,346 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,252 IT Pros & Developers. It's quick & easy.

Explanation of sending a "Response" (object?)

jbellis
P: 2
Can someone direct me to a good explanation or complete code example of sending a response from a perl script? I suspect that I don't even understand what's going on because web searches don't show what I'm expecting. For example, does the response automatically go to STDOUT so anything printed becomes "Response?" Do I need to write lines for every header item... content-type, length, etc.

Background: I've succeeded, with no perl skills, in creating a simple perl program that saves a file (some XML) to my web server in response to a Flash SWF actionscript command "send." If you're interested, see the Save button at http://s91524683.onlinehome.us/lexonomy/. But this command is one-way... no feedback. So now I'm trying to use a different command that receives (an XML structure in) the Response object. And I have no idea what the right code is, so I don't think it's helpful to show examples of what I've tried... just print statements. All I see on the web is vague mentions and snippets.
Thanks very much, Jack
Mar 5 '08 #1
Share this Question
Share on Google+
2 Replies


jbellis
P: 2
Solution... got it working with some advice from actionscript forum.... from the Help file:
In Flash:

Expand|Select|Wrap|Line Numbers
  1. var lv_Q:LoadVars = new LoadVars(); //object holding the data to send
  2. var lv_A:LoadVars = new LoadVars(); //object to hold the data received
  3.  
  4. lv_A.onLoad = function(success:Boolean) {
  5. if (success) {
  6. my_text.text = lv_A.responseVar; // display confirmation
  7. } else {
  8. my_text.text = "Error."; // script didnt load
  9. }
  10. }
  11.  
  12. lv_Q.sendAndLoad("yourscriptname.php", lv_A, "POST");
I had previously seen and used that same code, but I guess I never got it fully working. The .onload never fired success or failure. Possibly the function definition, which I hadn't copied verbatim. In retrospect I realize that meant my Actionscript was not functioning (because sendandload ensures an "onload" irrespective of one's CGI. Once I got it working, I was able to prove that Perl as simple as
Expand|Select|Wrap|Line Numbers
  1. print "Content-type:text/xml\n\n";
  2. print "...fromserver\n"
;
works, even without the #!/usr... line. So this means the answer to my original confusion is:
"Any print output from a Perl program to the default output (STDOUT standard output?) automatically becomes the 'response' that is sent back. You need only precede it with a content type statement"... or something along those lines.
Thanks, Jack
Mar 10 '08 #2

KevinADC
Expert 2.5K+
P: 4,059
I was able to prove that Perl as simple as
print "Content-type:text/xml\n\n";
print "...fromserver\n";
works, even without the #!/usr... line. So this means the answer to my original confusion is:
"Any print output from a Perl program to the default output (STDOUT standard output?) automatically becomes the 'response' that is sent back. You need only precede it with a content type statement"... or something along those lines.
Thanks, Jack
any "print" command not directed to a filehandle or other output device will print to STDOUT (standard output). That will be the content sent back from the server that you see displayed in the browser. It must be preceeded by an appropriate http header, such as "Content-type: text/xml\n\n". The two newlines are important: \n\n they signal the end of the http headers and the beginning of the content.
Mar 10 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.