PDA

View Full Version : HTTPS accept??


petey20
06-23-2004, 12:57 PM
Forgive me if this question is silly, but we are wanting to B2B transaction with a company that's sending us XML documents.
right now they are FTP'ing the XML documents to our server and we are processing them once they get there.

They want to use HTTPS instead of FTP now so I got my SSL certificate and it's installed on my server. Now they are trying to POST to my server.
Not much help on their end, but it's my understanding that I need to write a CGI or PHP script that accepts their post to our server?

Basically all I want to do is accept the post and place the XML doc in a directory on my FreeBSD server. Is there any examples of code that does this out there or has anyone done this?
OR am I totally off base. Basically they are ready to go and are waiting on me and I'm sitting here scratching my head

I'm Running Apache if it matters

Thanks in advance

firepages
06-23-2004, 02:54 PM
on the page they POST to , the XML should be available in



to test ... in(e.g.) grab.php ...

<?
if( !empty( $GLOBALS['HTTP_RAW_POST_DATA'] ) ){
header( 'Content-Type: text/xml' ) ;
echo $GLOBALS['HTTP_RAW_POST_DATA'] ;
}else{
print_r( $GLOBALS ) ;
}
?>

petey20
06-24-2004, 02:29 PM
Thanks for the code, but!!

This is no longer ther case. It's my understanding that they are sending a "Stream" of data through the "content" or body of the post. Meaning the part directly after the header.

They have the post function set up on their end but I have no clue how to accept their post. I'm writing a PHP script that they post to, that needs to read this data stream starting after the headers and write to a local XML file on my server.

So bascially it's a read and write. I've been looking at fsockopen(), fgets(), fread(), stream_get_line() and I'm not seeign the answer I need. There's TONS of examples on how to post, but nothing on how to accept the post. Excuse me if it's a simple answer or if I'm missing something. The fellow I'm working with on the other end is quite confusing and very hard to work with and hasn't given me much help. If he was transfering a file I'd been done 2 days ago

Anyone know how to accept a post like this and write the stream to a file?

firepages
06-24-2004, 03:15 PM
ok have you actually tried the above ? ...

almost all XML services/streams submit via POST and noramlly end up accessible via HTTP_RAW_POST_DATA

can you post one of thier POST examples ? it will give us a clue how to handle it.

petey20
06-24-2004, 05:37 PM
Actually that was the answer I needed.

Here's the ending code

<?php

if ( $GLOBALS['HTTP_RAW_POST_DATA'] != '' )
{
$filename = "/usr/home/matricftp/myfile" . time(). ".xml";
$fd = fopen($filename, "w");
if ( $fd === FALSE )
{
// Error cannot open file
} else {
if ( fwrite($fd, $GLOBALS['HTTP_RAW_POST_DATA']) === FALSE )
{
// Error cannot write to file
}
fclose($fd);
}
}

?>