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

发布于 2024-09-29 15:03:35 字数 891 浏览 4 评论 0原文

我在 Linux 服务器上通过 PHP/Soap 连接到 Web 服务。

问题是一个方法通过 SharpZipLib 压缩响应。所以我得到的只是一个乱码字符串。

有谁知道用 PHP 或 JS 解压这个文件的方法吗?

谢谢!

更新:

这是返回的压缩测试数据:

UEsDBC0AAAAIAI5TWz3XB/zi//////////8EABQAZGF0YQEAEADWAgAAAAAAABYBAAAAAAAAfZLvToNAEMTnUXyDatXEDxcS/3zxizH6BBVESaESKFHf3t+cOWgtNhcuYXd2Zndug570qjdV6rVVpxV3pQ9tlCnohv+ ab6Mc1J0G7kynZBb/5IKeYTDLAGOm28hVwtmpobqItfuYACpp1Ki42jobOGqO1eYRIXI2egHfofeOTqt7OE6o8QQdmbnpjMm01JXOdcG5ZKplVDpeEeBr6LCir2umKaJCj3ZSbGPEE3+NSD/57fADtfYhoRtwZq mJ/c3Z+bmaHl9Kzq6CX20bWRJzjvMNbtjZ71Fvtdfz2RjPY/2ESy54ExJjC6P78U74XYudOaw2gPUOTSyfRDut9cjLmGma2//24TBTwj85573zDhziFkc29wdQSwECLQAtAAAACACOU1s91w f84v ///////////BAAUAAAAAAAAAAAAAAAAAAAAZGF0YQEAEADWAgAAAAAAABYBAAAAAAAAUEsFBgAAAAABAAEARgAAAEwBAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=

I am on a linux server connecting to a webservice via PHP/Soap.

The problem is that a method is zipping the response via SharpZipLib. So all I get in return is a garbled string.

Does anyone know of a way to unzip this with PHP or 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=

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

短暂陪伴 2024-10-06 15:03:35

很可能,它正在使用 gzip。您应该查看 PHP Zlibgzdecodegzdeflate 方法。您可能需要查看内容类型标头或其他响应标头。

您还可以尝试在 Web 服务请求中设置 Accept 标头,告诉服务您不知道如何处理压缩。如果这是一项适当的服务,它将尊重该请求。

编辑查看 .pdf,他们将数据作为 zip 存档发送 - 因此您需要找到一个处理内存 zip 存档的 PHP 库。他们用来解码的 C# 代码非常简单 - 他们只是读取存档中的所有条目并展开它们。您可以尝试使用 PHP 包装器 以及 < a href="http://php.net/manual/en/ref.zip.php" rel="nofollow">PHP Zip。

您是否尝试设置要求不压缩的接受标头?

Chances are, it's using gzip. You should look into PHP Zlib and the gzdecode or gzdeflate methods. You'll probably need to look at the Content type header or another response header.

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. 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. The C# code they use to decode it is pretty straightforward - they just read all the entries in the archive and expand them. You can try storing it as an in memory buffer using a PHP wrapper along with PHP Zip.

Did you try setting an Accept Header that asks for no compression?

但可醉心 2024-10-06 15:03:35

您可以使用这样的函数解压缩字符串:

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

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;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文