简体   繁体   中英

php , How to decode / save a file from SOAP MTOM attachment?

I'm trying to get the content / save a zipfile returned by a webservice . However It seems that the API provides the file encoded in Base64 Binary format and included in the response according to the SOAP MTOM standard. I've tried some workarounds for 2 hours so any help would be highly appreciated . The response looks like this :

--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

I hope this helps someone ... I simply removed all the markup code/mime type xml etc before the messy characters and saved the content as a .zip file . It's not an ideal solution but it works.

--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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM