2012-05-15 92 views
1

我想獲取內容/保存web服務返回的zip文件。但是,API似乎提供了以Base64二進制格式編碼的文件,並且根據SOAP MTOM標準包含在響應中。我已經嘗試了2個小時的一些解決方法,所以任何幫助將不勝感激。響應看起來是這樣的:php,如何從SOAP MTOM附件解碼/保存文件?

--MIMEBoundaryurn_uuid_9ADB5E0C3BD2353F98133706376435374151 
Content-Type: application/xop+xml; charset=utf-8; type="text/xml" 
Content-Transfer-Encoding: binary 
Content-ID: <0.urn:uuid:9ADB5E0C3BD2353F98133706376435374152> 
<?xml version='1.0' encoding='UTF-8'?><downloadFileResponse xmlns="http://www.pe.com/marketplace/services"><ack>Success</ack><version>1.1.0</version><timestamp>2012-05-15T06:36:04.353Z</timestamp><fileAttachment><Size>3204907</Size><Data><xop:Include xmlns:xop="http://www.w3.org/2004/08/xop/include" href="cid:urn:uuid:FED4FAD1B1E74C8B391337063821260"/></Data></fileAttachment></downloadFileResponse> 

--MIMEBoundaryurn_uuid_9ADB5E0C3BD2353F98133706376435374151 
Content-Type: application/zip 
Content-Transfer-Encoding: binary 
Content-ID: <urn:uuid:FED4FAD1B1E74C8B391337063821260> 
here is some messy code ADASLKDAKDNAKJDNAKDNKJNDSAKDJNAKDJADA which is actually the file content itself 

回答

1

我希望這可以幫助別人。我只是刪除了所有的標記代碼/ MIME類型的XML等之前凌亂的人物和保存的內容作爲一個.zip文件。這不是一個理想的解決方案,但它的作品。

--MIMEBoundaryurn_uuid_9ADB5E0C3BD2353F98133706376435374151 
Content-Type: application/xop+xml; charset=utf-8; type="text/xml" 
Content-Transfer-Encoding: binary 
Content-ID: <0.urn:uuid:9ADB5E0C3BD2353F98133706376435374152> 
<?xml version='1.0' encoding='UTF-8'?><downloadFileResponse xmlns="http://www.pe.com/marketplace/services"><ack>Success</ack><version>1.1.0</version><timestamp>2012-05-15T06:36:04.353Z</timestamp><fileAttachment><Size>3204907</Size><Data><xop:Include xmlns:xop="http://www.w3.org/2004/08/xop/include" href="cid:urn:uuid:FED4FAD1B1E74C8B391337063821260"/></Data></fileAttachment></downloadFileResponse> 

--MIMEBoundaryurn_uuid_9ADB5E0C3BD2353F98133706376435374151 
Content-Type: application/zip 
Content-Transfer-Encoding: binary 
Content-ID: <urn:uuid:FED4FAD1B1E74C8B391337063821260> 
+0

好吧,更好的方法應該是使用[PEAR Mail_MIME](http://pear.php.net/package/Mail_Mime/)擴展名。無論如何感謝分享 –