2011-07-21 31 views
0

我無法弄清楚如何有效地獲得多部分http響應的特定部分。 我試圖通過在PHPCURL上發送SOAP來從Jasper Reports服務器獲取PDF報告,並且我沒有在CURL文檔中找到如何處理多部分響應。 我想在下面獲得'報告'部分的RAW迴應。 感謝您的幫助。 伊利亞斯如何通過Content-Id獲取多部分響應的附件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

也許http://www.php.net/manual/en/function.mailparse-msg-get-part.php? –

+0

閱讀以前的問題/答案:http://stackoverflow.com/questions/541430/how-do-i-read-any-request-header-in-php – Brian

回答

0

我修改了一點SHEF的解決方案這樣的:

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

而且現在的工作。謝謝Shef。

0

試試這個:

<?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]; 
?> 

不過,我也不會保證其可靠性,因爲返回的字符串的結構可能會隨時改變。