Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Perl and http headers etc...

Status
Not open for further replies.

lukosanthropos

Programmer
Mar 10, 2009
3
GB
Right first I've been programming perl for what seems like forever but only do a couple of simple tasks, I am now trying to branch out into cgi scripting, my current issue is I cannot for the life of me figure out how to get perl to extract headers [my google-fu has failed me]

A bit of background, I have interfaced with a couple of simple API's in the past using PHP curl, sending requests and processing the responses, I am now trying to write both sides of this thing in perl so I need to know how to send data (lets for the sake of argument say I'm sending a simple bit of XML) I need to know how to both send that data and on the other side receive it, I know what to do with it once that has been handled but I can't for the life of me figure it out


I would appreciate any pointers (not programming for 16 hours straight in a new language is a good pointer, also probably why I'm so frazzled) or example code, (example code is best as it is made of win)

Thanks in advance
 
Do you want to use a web server or are you trying to send it over it's own socket?

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[noevil]
Travis - Those who say it cannot be done are usually interrupted by someone else doing it; Give the wrong symptoms, get the wrong solutions;
 
Well, for the sending side, essentially all you need to do is print:
Code:
#!/usr/local/bin/perl

print "Content-type: text/xml\n\n"; # Put this at the start of your document
print "<myelement>hello world!</myelement>\n";
If you need to do stuff like handle parameters passed to your script, use the cgi.pm module
Code:
#!/usr/local/bin/perl
use CGI;

$q = new CGI;
$p1 = $q->param('p1');
print $q->header(-type=>"text/xml"); # You can print headers like this too
print "<myelement p1=\"$p1\">hello world!</myelement>\n";
More detail on this module at
For the receiving side, you'll need to use the LWP module. is a place to get started.

Apart from printing a content type when you're outputting, you don't really need to tangle with http headers, unless you're doing something out of the ordinary.

Hopefully that's put you on the right track and given you a few terms to Google on.


-- Chris Hunt
Webmaster & Tragedian
Extra Connections Ltd
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top