Page 1 of 1

http_post ... receive

Posted: Thu Jun 03, 2004 2:35 am
by bernard74
hello,
I must receive an xml file with http_post.
my pb is that the xml file can contains some line than :
<line1>L'ASSURANCE N'EST PAS COMPRISE</line1>
instead of
<line1>L'ASSURANCE N'EST PAS COMPRISE</line1>
and i don't know how to solve my pb !
I try to use :
while(list($indice,$valeur) = each($HTTP_POST_VARS))
but i never see my complete file !

the complete post is :
"AUTH_USER=username&AUTH_PASS=password&AUTH_XML=".$data

All is ok for AUTH_USER, AUTH_PASS, but wrong for AUTH_XML

Thanks for your help

Bernard

Posted: Thu Jun 03, 2004 3:47 am
by patrikG
not sure what your "pb" means.

Use $_POST instead of $HTTP_POST_VARS and [php_man]html_entity_decode[/php_man] should help you with the encoded string (xml-tag <line1>...</line1>

http_post

Posted: Thu Jun 03, 2004 4:30 am
by bernard74
I have always the probleme :

My input data is :

<?xml version="1.0"?>
<Line1>L'ASSURANCE DE TRANSPORT N'EST PAS A COUVRIR </Line1>

while(list($indice,$valeur) = each($_POST))
{
$valeur=html_entity_decode ($valeur,ENT_NOQUOTES, "ISO-8859-15");
print "VALEUR=".$valeur."\n";
}

The resultat is :
VALEUR=<?xml version=\"1.0\"?>
<Line1>L

Posted: Thu Jun 03, 2004 4:39 am
by patrikG
You need to parse the XML file first (use XPath or XLST) - have a look at these threads:

viewtopic.php?t=20644
viewtopic.php?t=19668

Some tutorials on XML and PHP are here.

Once you've extracted the values from the XML-file, you can use html_entity_decode on them.

receive

Posted: Thu Jun 03, 2004 5:21 am
by bernard74
yes ... but i can't parse before receiving the data ... and i don't receive all the data, as you see in my example.
This is my probleme.

Posted: Thu Jun 03, 2004 5:24 am
by bernard74
==> I have to try to change the arg_separator.input in .htaccess, but nothing change :

php_value arg_separator.input "@"

Posted: Thu Jun 03, 2004 5:25 am
by patrikG
What would be the point of posting an incomplete XML-document?

In terms of workflow, I assume the following:

1. retrieval of complete XML-document
2. parsing of XML
3. value normalisation (e.g. html_entity_decode etc.)

Otherwise, the whole thing seems a bit non-sensical to me.

receive

Posted: Thu Jun 03, 2004 6:48 am
by bernard74
Hi,
I give you my complete code, before calling the parser.
I don't understand what is wrong !
Thanks for your kindness and your help
.. and excuse me for my vey bad English .....
Bernard

Code: Select all

<?php
// sender.php 
//1) PROGRAM USE TO SEND DATA TO THE SERVER (CLIENT)
$fic=$argv[1];
$fp = fopen($fic,"r");
$data="";
$data=fread($fp,filesize($fic));
fclose($fp);
$postvars="AUTH_USER=username&AUTH_PASS=password&AUTH_XML=".$data;
$ch=curl_init();
 curl_setopt($ch, CURLOPT_URL, "http://bpinf.dyndns.org/receive");
 curl_setopt($ch, CURLOPT_POST, 1);
 curl_setopt($ch, CURLOPT_POSTFIELDS, $postvars);
 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
?>
   
2) THE DATA (passed as argv[1] to sender.php)
<?xml version="1.0"?>
    <ImportantRemarks>
      <Line1>L'ASSURANCE DE TRANSPORT N'EST PAS A COUVRIR      </Line1>
    </ImportantRemarks>

1) PROGRAM USE TO RECEIVE DATA
<?php
// index.php
// is username ok ?
if (!isset($HTTP_POST_VARS['AUTH_USER']))
{
   $buffaux="*NOK* USER ABSENT <br>\n";
   print $buffaux;
   exit(1);
} 
else
{
   $zuser = $HTTP_POST_VARS['AUTH_USER'];
   if ($zuser <> "userrname")
   {
      $buffaux="*NOK* USER INVALIDE ".$zuser."<br>\n";
      print $buffaux;
      exit(1);
   } 
} 
// is password ok ?
if (!isset($HTTP_POST_VARS['AUTH_PASS']))
{
   $buffaux="*NOK* PASSWORD ABSENT <br>\n";
   print $buffaux;
   exit(1);
} 
else
{
   $zpass = $HTTP_POST_VARS['AUTH_PASS'];
   if ($zpass <> "password")
   {
      $buffaux="*NOK* PASSWORD INVALIDE ".$zpass."<br>\n";
      print $buffaux;
      exit(1);
   } 
} 
// Controle si presence du fichier xml
if (!isset($HTTP_POST_VARS['AUTH_XML']))
{
   $buffaux="*NOK* FICHIER ABSENT <br>\n";
   print $buffaux;
   exit(1);
} 
else
{
   $zfic = $HTTP_POST_VARS['AUTH_XML'];
   $zfic = str_replace('"', '"', $zfic);
} 

$today=date("YmdHis");
$file = "xml.".$today.".tmp";

// All is ok, now we can parse the file
$fp = fopen($file, "w");
fputs($fp, $zfic);
fclose($fp);

// call the parser (when the data is received, the parser work fine)
// but if the data contain characters like ', the data is not received correctly
print "*OK* <br>\n";
exit(0);
?>