0

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=

James Donnelly
  • 126,410
  • 34
  • 208
  • 218
Fostah
  • 2,947
  • 4
  • 56
  • 78
  • is it using zip, gzip, tar, or bzip2? – NG. Oct 28 '10 at 22:27
  • I'm not sure the type of compression. On page 26 of http://forums.regonline.com/forums/docs/RegOnlineWebServices.pdf they provide the code for .NET but I dont see any reference to the type of compression. – Fostah Oct 29 '10 at 16:31

2 Answers2

2

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?

NG.
  • 22,560
  • 5
  • 55
  • 61
  • Although I'd hope the client is smart enough to automatically deal with HTTP compression. Guess not ... or it's a zip inside the stream. –  Oct 28 '10 at 23:27
  • Thanks! I have tried gzdeflate and gzuncompress but both seem to return data errors or garbled text. Could this have to do with the level of compression? Warning: gzuncompress() [function.gzuncompress]: data error in /home/npculti/public_html/unzip/unzip.php on line 6 – Fostah Oct 29 '10 at 16:35
  • Also I get a function not found on gzdecode, so if that was it I would just need to install it and try it. I have attached the compressed string I get to the question as well. Thanks for any help! – Fostah Oct 29 '10 at 16:36
  • I just tried a gzdecode function I found and it returns the same compressed string. function gzdecode($data){ $g=tempnam('/tmp','ff'); @file_put_contents($g,$data); ob_start(); readgzfile($g); $d=ob_get_clean(); return $d; } – Fostah Oct 29 '10 at 16:53
  • Hey SB, Thanks for your comments I am still working on getting ZipArchive setup on the server I'm on to test this. I will report back. – Fostah Nov 03 '10 at 18:15
1

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