简体   繁体   English

在PHP或JS中解压缩SharpZipLib字符串?

[英]Decompress SharpZipLib string in php or JS?

I am on a linux server connecting to a webservice via PHP/Soap. 我在通过PHP / Soap连接到Web服务的Linux服务器上。

The problem is that a method is zipping the response via SharpZipLib. 问题是方法通过SharpZipLib压缩响应。 So all I get in return is a garbled string. 因此,我得到的只是一个乱码。

Does anyone know of a way to unzip this with PHP or JS? 有谁知道用PHP或JS解压缩它的方法吗?

Thanks! 谢谢!

Update: 更新:

This is the compressed test data that gets returned: 这是返回的压缩测试数据:

UEsDBC0AAAAIAI5TWz3XB/zi//////////8EABQAZGF0YQEAEADWAgAAAAAAABYBAAAAAAAAfZLvToNAEMTnUXyDatXEDxcS/3zxizH6BBVESaESKFHf3t+cOWgtNhcuYXd2Zndug570qjdV6rVVpxV3pQ9tlCnohv+ab6Mc1J0G7kynZBb/5IKeYTDLAGOm28hVwtmpobqItfuYACpp1Ki42jobOGqO1eYRIXI2egHfofeOTqt7OE6o8QQdmbnpjMm01JXOdcG5ZKplVDpeEeBr6LCir2umKaJCj3ZSbGPEE3+Nsd/57fADtfYhoRtwZqmJ/c3Z+bmaHl9Kzq6CX20bWRJzjvMNbtjZ71Fvtdfz2RjPY/2ESy54ExJjC6P78U74XYudOaw2gPUOTSyfRDut9cjLmGma2//24TBTwj85573zDhziFkc29wdQSwECLQAtAAAACACOU1s91wf84v//////////BAAUAAAAAAAAAAAAAAAAAAAAZGF0YQEAEADWAgAAAAAAABYBAAAAAAAAUEsFBgAAAAABAAEARgAAAEwBAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA= UEsDBC0AAAAIAI5TWz3XB / ZI ////////// 8EABQAZGF0YQEAEADWAgAAAAAAABYBAAAAAAAAfZLvToNAEMTnUXyDatXEDxcS / 3zxizH6BBVESaESKFHf3t + cOWgtNhcuYXd2Zndug570qjdV6rVVpxV3pQ9tlCnohv + ab6Mc1J0G7kynZBb / 5IKeYTDLAGOm28hVwtmpobqItfuYACpp1Ki42jobOGqO1eYRIXI2egHfofeOTqt7OE6o8QQdmbnpjMm01JXOdcG5ZKplVDpeEeBr6LCir2umKaJCj3ZSbGPEE3 + NSD / 57fADtfYhoRtwZqmJ / C3Z + bmaHl9Kzq6CX20bWRJzjvMNbtjZ71Fvtdfz2RjPY / 2ESy54ExJjC6P78U74XYudOaw2gPUOTSyfRDut9cjLmGma2 // 24TBTwj85573zDhziFkc29wdQSwECLQAtAAAACACOU1s91wf84v ////////// BAAUAAAAAAAAAAAAAAAAAAAAZGF0YQEAEADWAgAAAAAAABYBAAAAAAAAUEsFBgAAAAABAAEARgAAAEwBAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA =

Chances are, it's using gzip. 可能是,它正在使用gzip。 You should look into PHP Zlib and the gzdecode or gzdeflate methods. 您应该研究PHP Zlibgzdecodegzdeflate方法。 You'll probably need to look at the Content type header or another response header. 您可能需要查看Content类型标头或另一个响应标头。

Something you can try is also setting an Accept header in the web service request that tells the service you don't know how to deal with compression. 您还可以尝试在Web服务请求中设置一个Accept标头,该标头告诉服务您不知道如何处理压缩。 If it's a proper service, it will honor the request. 如果服务适当,它将兑现请求。

EDIT Looking at the .pdf, they're sending the data as a zip archive - so you need to find a PHP lib that deals with in memory zip archives. 编辑查看.pdf,他们将数据作为zip存档发送-因此您需要找到一个处理内存zip存档的PHP库。 The C# code they use to decode it is pretty straightforward - they just read all the entries in the archive and expand them. 他们用来解码的C#代码非常简单-他们只是读取存档中的所有条目并进行扩展。 You can try storing it as an in memory buffer using a PHP wrapper along with PHP Zip . 您可以尝试使用PHP包装器PHP Zip将其存储为内存缓冲区。

Did you try setting an Accept Header that asks for no compression? 您是否尝试设置不要求压缩的接受标头?

You can unzip your string using such function: 您可以使用以下功能将字符串解压缩:

function decode($data)
{
    $filename = tempnam('/tmp', 'tempfile');
    file_put_contents($filename, base64_decode($data));

    $zip = zip_open($filename);
    $entry = zip_read($zip);

    $decoded = zip_entry_read($entry);

    zip_entry_close($entry);
    zip_close($zip);

    return $decoded;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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