XML : <erreur> Le Content type doit etre : text/xml </erreur> avec CURL et PHP
Bonjour a tous, je suis en train de créer un fichier PHP qui va générer un fichier xml qui sera enfin envoyé sur un serveur distant.
Le pb que je rencontre c'est que je reçois la réponse suivante :
Code:
1 2 3 4 5 6 7 8 9 10 11
| <html>
<head>
</head>
<body>
<a href="http://www.xxxxx.fr/export_DUPONT_Olivier_1.xml" target="_blank"> Voir fichier</a>
<validation_serveur>
<erreur>
Le Content type doit etre : text/xml
</erreur>
</validation_serveur>
</body></html> |
j'ai beau chercher sur gg il semblerait qu'il faille rajouter le header content, mais quelque soit l'endroit ou je le mets ça ne marche pas , si vous pouviez s'il vous plait m'aider, voici mon code :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
| <?php
session_start();
include ('config.php');
$id=@$_GET['id'];
header("Content-Type: text/xml");
header("Cache-Control: no-cache, must-revalidate");
$result_table= mysql_query("SELECT * FROM tablewhere id='$id'");
$num_table = mysql_num_rows($result_table);
if ($num_table != 0) {
while ($row = mysql_fetch_array($result_table)) {
$file= fopen("export_$row[nom_e]_$row[prenom_e]_$row[id].xml", "w");
$_xml ="<?xml version=\"1.0\" encoding=\"utf-8\"?>";
$_xml .="";
$_xml .="<DOSSIER>
..... toutes les balises ....
</DOSSIER>";
echo '<html>
<head>
</head>
<body>
<a href="http://'. $url_index.'/export_'.$row["nom_e"].'_'.$row["prenom_e"].'_'.$row["id"].'.xml" target="_blank"> Voir fichier xml </a>
';
$nom_xml=$row["nom_e"].'_'.$row["prenom_e"].'_'.$row["id"];
// $_xml .="header('Content-Type: text/xml')";
}
// echo $_xml;
fwrite($file, $_xml);
fclose($file);
/*
* XML Sender/Client.
*/
$file = 'http://'. $url_index.'/export_'.$nom_xml.'.xml';
if(!$xml_builder = simplexml_load_file($file))
exit('Failed to open '.$file);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://urlduserveur");
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/xml'));
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml_builder);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
curl_setopt($ch, CURLOPT_REFERER, 'https://urlduserveur');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$ch_result = curl_exec($ch);
curl_close($ch);
// Print CURL result.
echo $ch_result;
}
echo '</body></html>';
?> |
Merci milles fois de votre aide
olivier