averylongloginname has asked for the wisdom of the Perl Monks concerning the following question:

Edited by Corion : Removed <pre> tags.

okay, here's the deal. My web server is interacting with another web server via https. This other web server is eventually going to send an XML page back to my url. my job: parse this page. My question is not how to parse XML, but how to get the page in the first place. I deal mainly with cgi parameters and this is the first time I've had to do this.

Most XML examples I've seen already have some generic xml file defined (ie: $file = c:\temp\files\example.xml), but my problem is getting this file in the first place. Should I use IO::Socket to 'listen' on port 443, then use XML::Parser to parse the 'stream'? Not sure if I'm looking in the right direction here. Your help would be greatly appreciated - or at least point me in the right direction.

Thanks.
'..Tis not a man - tis a remorseless eating machine...argghh'

Replies are listed 'Best First'.
Re: xml stream
by Fastolfe (Vicar) on Jan 24, 2001 at 00:45 UTC
    What do you mean by "back to my URL"? Is this going to be a fairly simple HTTP transaction, where your script will request a resource from this other server via HTTP, and that HTTP response will be an XML document? Or are you talking about initiating the construction of this XML document, and awaiting the other end to establish a TCP connection to you to deliver it? Will this latter response be via HTTP also (to your web server), or just a simple TCP data stream sent to some high numbered port? Will this "response connection" be over SSL?

    I suspect and hope that you don't mean "back to my URL" the way it sounds, and that this XML reply will be delivered just as any other HTTP request/response would be. In this case, use LWP (or perhaps LWP::Simple) to do it. You will likely need to install an SSL library such as OpenSSL to make use of HTTPS URL's, which makes it a bit harder to do.

Re: xml stream
by arturo (Vicar) on Jan 24, 2001 at 00:40 UTC

    To get a file via HTTP(S?), use one of the LWP family of modules.

    Philosophy can be made out of anything. Or less -- Jerry A. Fodor

Re: xml stream
by lzcd (Pilgrim) on Jan 24, 2001 at 05:30 UTC
    Not trying to be painful here but could you refrain from using the <code> tags unless you're actually posting code?

    It's makes for easier reading and a higher chance of people actually noticing your question as opposed to the bad use of a monospaced font.

Re: xml stream
by sierrathedog04 (Hermit) on Jan 24, 2001 at 06:17 UTC
    The way I choose to accomplish this task is I create an HTML form on the server that is to send the XML. This form has a hidden field. This hidden field is a long string of XML.

    The sender then posts the form.

    I then read the hidden field of XML and pass it to the parser of my choice as a string. XML::DOM and other parsers can read a string of XML instead of a file if you ask it to.

      I am not sure if that is the best way of doing it. I don't like hidden form fields except where "necessary", but I think that a long string of XML in a hidden form would be a bit messy and this would require user interaction. Also it would be a pain if you wanted different XML sent at different times.

      My choice would be to do the following:
      1. Think of it as requesting the XML from the "other server" (the other way round is more complex)
      2. Have a script (or static XML file) on the "other server" that simply produces\displays the XML. Secure this with password protection if necessary.
      3. Have the script on "local" server use an LWP module to request the XML from the other server. This will usually take less than 5 lines of coding =)
      4. Parse the XML.

      I think that this is basically what the reader has asked for. If you do it this way, then you can schedule\automate the task of grabbing the XML and parsing it very easily. I do advise to secure the XML output of the "other server" script if it contains sensitive data.

      $code or die
      Using perl at
      The Spiders Web

      Update: Besides standard LWP docs, see use LWP::Protocol::https for some info and sample script, and also look up Net::SSLeay and Crypt::SSLeay on CPAN