2011-07-21 3 views
0

Je ne peux pas comprendre comment obtenir efficacement une partie spécifique d'une réponse http multipart. J'essaie d'obtenir un rapport PDF du serveur Jasper Reports en envoyant SOAP sur PHPCURL et je n'ai pas trouvé dans la documentation de CURL comment gérer la réponse multi-parties. J'aimerais obtenir une partie de la réponse RAW ci-dessous. Merci pour toute aide. IlyasComment obtenir par Content-Id les pièces jointes d'une réponse multipart avec PHP CURL

------=_Part_6_9317140.1311257231623 
Content-Type: text/xml; charset=UTF-8 
Content-Transfer-Encoding: binary 
Content-Id: <B33D7700BFCF12CC2A64A7F6FB84CEAE 

sutffs here 
------=_Part_6_9317140.1311257231623 
Content-Type: application/pdf 
Content-Transfer-Encoding: binary 
Content-Id: <**report**> 

binary PDF content here 
+2

Peut-être http://www.php.net/manual/fr/fonction.mailparse-msg-get-part.php? –

+0

Vous avez lu cette question précédente: http://stackoverflow.com/questions/541430/how-do-i-read-any-request-header-in-php – Brian

Répondre

0

J'ai modifié la solution un peu Shef comme ça:

$pattern = "/report>\r\n\r\n/"; 
$matches = preg_split($pattern, $output); 
file_put_contents('c:/report.pdf', $matches[1]); 

Et ça marche maintenant. Merci Shef.

0

Essayez ceci:

<?php 
$str = '------=_Part_6_9317140.1311257231623 
Content-Type: text/xml; charset=UTF-8 
Content-Transfer-Encoding: binary 
Content-Id: <B33D7700BFCF12CC2A64A7F6FB84CEAE 

sutffs here 
------=_Part_6_9317140.1311257231623 
Content-Type: application/pdf 
Content-Transfer-Encoding: binary 
Content-Id: <**report**> 

binary PDF content here'; 

$pattern = '%Content-Type: application/pdf'."\n". 
      'Content-Transfer-Encoding: binary'."\n". 
      'Content-Id: ([^\s]+)%'; 

preg_match($pattern, $str, $matches); 
echo $matches[1]; 
?> 

Cependant, je ne porte garant pour sa fiabilité, car la structure de la chaîne retournée peut changer à tout moment.

Questions connexes