recieve zip file via xml

Discussion in 'XML' started by asis.morodo@drunpe.com, Dec 24, 2007.

  1. Guest

    Hey guys,

    I am connecting to a supllier via SOAP that sends me with the price
    list zipped inside an xml message. I can connect and I can retrieve
    the xml information (see the message, save the content, etc...)
    however i am unable to unzip the information contained in the tag

    here is my code:

    <code>
    <?php

    $client = new SoapClient("mywsdl service",array('trace' => 1));

    $call = $client->__soapCall("Cliente",
    array('Cliente'=>array('ncliente'=>"user",'pss'=>"password")));

    //Some debugging

    echo("\r\nCabecera de la solicitud:\n" .$client-
    >__getLastRequestHeaders());


    echo("\r\nSolicitud:\n".$client->__getLastRequest());

    echo("\r\nCabecera de Respuesta:\n" . $client-
    >__getLastResponseHeaders());


    echo ("\r\nRespuesta:" . $client->__getLastResponse());


    $myFile = "prueba.zip";
    $fh = fopen($myFile, 'wb');

    fwrite($fh, $call->ClienteRespuesta);

    fclose($fh);

    ?>
    </code>

    When i try to open the file with zip i get an error. the file has
    1024kb so I know there is info in there but i just dont know how to
    access it. I have also tried to base64_decode manually before the SOAP
    parses the info with no luck.

    Thank you for any help.
     
    , Dec 24, 2007
    #1
    1. Advertising

  2. Dikkie Dik Guest

    > $myFile = "prueba.zip";
    > $fh = fopen($myFile, 'wb');
    >
    > fwrite($fh, $call->ClienteRespuesta);


    If this really is a SOAP service, it will contain XML. There are a few
    ways to send binaries with XML, but a SOAP service will never send a
    pure binary as far as I know.

    > When i try to open the file with zip i get an error. the file has
    > 1024kb so I know there is info in there but i just dont know how to
    > access it. I have also tried to base64_decode manually before the SOAP
    > parses the info with no luck.


    Just take a look at the saved file. If there is any base64 encoded data
    inside, it is given within XML tags. So again, it is not the whole response.

    But there is also the possibility that it is an attachment. In that
    case, the response is a multipart download. I do not know the SOAP
    library enough to be able to tell you if it can handle that. If it can
    (which would not surprise me), there is probably a method of the client
    object that gives you access to the attachments.

    Good luck and a nice christmas,
    Dikkie
     
    Dikkie Dik, Dec 24, 2007
    #2
    1. Advertising

  3. Guest

    Thanks Dikkie,

    With soap i do retrieve an xml file which i save into $call. I can
    reference the tags directly, since the information I want is in the
    ClienteRespuesta tag, I write it directly into the file.
    fwrite($fh, $call->ClienteRespuesta);

    > Just take a look at the saved file. If there is any base64 encoded data
    > inside, it is given within XML tags. So again, it is not the whole response.


    AFAIK soap decodes base64 when you access the xml tag. in any case i
    have tried decoding manually by debugging the response with the same
    result. As you can see in the code above I am extracting the data from
    the tags, so there are no tags in the file.

    If the file is an attachment how would you handle with xml, i havent
    seen anything in soap.


    Thanks again and Happy Christmas to you too.
     
    , Dec 24, 2007
    #3
  4. shimmyshack Guest

    On Dec 24, 1:03 pm, wrote:
    > Thanks Dikkie,
    >
    > With soap i do retrieve an xml file which i save into $call. I can
    > reference the tags directly, since the information I want is in the
    > ClienteRespuesta tag, I write it directly into the file.
    >  fwrite($fh, $call->ClienteRespuesta);
    >
    > > Just take a look at the saved file. If there is any base64 encoded data
    > > inside, it is given within XML tags. So again, it is not the whole response.

    >
    > AFAIK soap decodes base64 when you access the xml tag. in any case i
    > have tried decoding manually by debugging the response with the same
    > result. As you can see in the code above I am extracting the data from
    > the tags, so there are no tags in the file.
    >
    > If the file is an attachment how would you handle with xml, i havent
    > seen anything in soap.
    >
    > Thanks again and Happy Christmas to you too.


    it might sound silly, but have you checked out the "raw" response xml
    packet in a text editor. That way you get to see exactly what is being
    returned, you can then judge whether $call->ClienteRespuesta is enough
    to get at the encoded data. After all its the service creator that
    ultimately gets to decide how the zip is sent, it's their
    documentation that will provide the best answers here. do they
    <tag><![CDATA[base64encode(zip)]]></tag>
    or
    <tag typeofencoding="base43withnobson"><![CDATA[strangestuffhere]]></
    tag>
    or something weirder
     
    shimmyshack, Dec 24, 2007
    #4
  5. Guest

    On Dec 24, 10:51 pm, shimmyshack <> wrote:
    > On Dec 24, 1:03 pm, wrote:
    >
    >
    >
    >
    >
    > > Thanks Dikkie,

    >
    > > With soap i do retrieve an xml file which i save into $call. I can
    > > reference the tags directly, since the information I want is in the
    > > ClienteRespuesta tag, I write it directly into the file.
    > >  fwrite($fh, $call->ClienteRespuesta);

    >
    > > > Just take a look at the saved file. If there is any base64 encoded data
    > > > inside, it is given within XML tags. So again, it is not the whole response.

    >
    > > AFAIK soap decodes base64 when you access the xml tag. in any case i
    > > have tried decoding manually by debugging the response with the same
    > > result. As you can see in the code above I am extracting the data from
    > > the tags, so there are no tags in the file.

    >
    > > If the file is an attachment how would you handle with xml, i havent
    > > seen anything in soap.

    >
    > > Thanks again and Happy Christmas to you too.

    >
    > it might sound silly, but have you checked out the "raw" response xml
    > packet in a text editor. That way you get to see exactly what is being
    > returned, you can then judge whether $call->ClienteRespuesta is enough
    > to get at the encoded data. After all its the service creator that
    > ultimately gets to decide how the zip is sent, it's their
    > documentation that will provide the best answers here. do they
    > <tag><![CDATA[base64encode(zip)]]></tag>
    > or
    > <tag typeofencoding="base43withnobson"><![CDATA[strangestuffhere]]></
    > tag>
    > or something weirder- Hide quoted text -
    >
    > - Show quoted text -


    I have, with the debuggin message within the code I can see exactly
    what is being transmitted. Unfortunately this is no much use sine the
    data is base64 encoded and if decoded it´s still garbage since it´s a
    zip encoded stream.

    Whether or not they are enclosing the information in CDATA, Im afraid
    they´re not. I will contact them see if I can get them to add that.

    Thank you for your help.

    Asis
     
    , Dec 25, 2007
    #5
  6. shimmyshack Guest

    On Dec 25, 10:19 pm, wrote:
    > On Dec 24, 10:51 pm, shimmyshack <> wrote:
    >
    >
    >
    >
    >
    > > On Dec 24, 1:03 pm, wrote:

    >
    > > > Thanks Dikkie,

    >
    > > > With soap i do retrieve an xml file which i save into $call. I can
    > > > reference the tags directly, since the information I want is in the
    > > > ClienteRespuesta tag, I write it directly into the file.
    > > >  fwrite($fh, $call->ClienteRespuesta);

    >
    > > > > Just take a look at the saved file. If there is any base64 encoded data
    > > > > inside, it is given within XML tags. So again, it is not the whole response.

    >
    > > > AFAIK soap decodes base64 when you access the xml tag. in any case i
    > > > have tried decoding manually by debugging the response with the same
    > > > result. As you can see in the code above I am extracting the data from
    > > > the tags, so there are no tags in the file.

    >
    > > > If the file is an attachment how would you handle with xml, i havent
    > > > seen anything in soap.

    >
    > > > Thanks again and Happy Christmas to you too.

    >
    > > it might sound silly, but have you checked out the "raw" response xml
    > > packet in a text editor. That way you get to see exactly what is being
    > > returned, you can then judge whether $call->ClienteRespuesta is enough
    > > to get at the encoded data. After all its the service creator that
    > > ultimately gets to decide how the zip is sent, it's their
    > > documentation that will provide the best answers here. do they
    > > <tag><![CDATA[base64encode(zip)]]></tag>
    > > or
    > > <tag typeofencoding="base43withnobson"><![CDATA[strangestuffhere]]></
    > > tag>
    > > or something weirder- Hide quoted text -

    >
    > > - Show quoted text -

    >
    > I have, with the debuggin message within the code I can see exactly
    > what is being transmitted. Unfortunately this is no much use sine  the
    > data is base64 encoded and if decoded it´s still garbage since it´s a
    > zip encoded stream.
    >
    > Whether or not they are enclosing the information in CDATA, Im afraid
    > they´re not. I will contact them see if I can get them to add that.
    >
    > Thank you for your help.
    >
    > Asis- Hide quoted text -
    >
    > - Show quoted text -


    well CDATA isnt needed if it IS base64encoded as there will never be
    any illegal xml characters. (< or &)
    however if the stream you get when base64decoding is binary you do
    need to know what it is, might it be gzipped rather than a zip. You
    can test this by saving the binary within your server root somewhere
    public as
    test.txt.gz
    and trying to retrieve it from a browser, the browser should
    uncompress the stream and render the text. If it is just "corrupt"
    meaning you cannot see any part of it using a hex editor then the
    documentation from the developers of the service should say what
    format it is, they really ought to provide some kind of "test" service
    a known call and a known response, with a response already saved you
    can calculate the md5 of both that way to compare.
     
    shimmyshack, Dec 27, 2007
    #6
  7. Guest

    On 27 dic, 01:02, shimmyshack <> wrote:
    > On Dec 25, 10:19 pm, wrote:
    >
    >
    >
    >
    >
    > > On Dec 24, 10:51 pm, shimmyshack <> wrote:

    >
    > > > On Dec 24, 1:03 pm, wrote:

    >
    > > > > Thanks Dikkie,

    >
    > > > > With soap i do retrieve an xml file which i save into $call. I can
    > > > > reference the tags directly, since the information I want is in the
    > > > > ClienteRespuesta tag, I write it directly into the file.
    > > > >  fwrite($fh, $call->ClienteRespuesta);

    >
    > > > > > Just take a look at the saved file. If there is any base64 encoded data
    > > > > > inside, it is given within XML tags. So again, it is not the whole response.

    >
    > > > > AFAIK soap decodes base64 when you access the xml tag. in any case i
    > > > > have tried decoding manually by debugging the response with the same
    > > > > result. As you can see in the code above I am extracting the data from
    > > > > the tags, so there are no tags in the file.

    >
    > > > > If the file is an attachment how would you handle with xml, i havent
    > > > > seen anything in soap.

    >
    > > > > Thanks again and Happy Christmas to you too.

    >
    > > > it might sound silly, but have you checked out the "raw" response xml
    > > > packet in a text editor. That way you get to see exactly what is being
    > > > returned, you can then judge whether $call->ClienteRespuesta is enough
    > > > to get at the encoded data. After all its the service creator that
    > > > ultimately gets to decide how the zip is sent, it's their
    > > > documentation that will provide the best answers here. do they
    > > > <tag><![CDATA[base64encode(zip)]]></tag>
    > > > or
    > > > <tag typeofencoding="base43withnobson"><![CDATA[strangestuffhere]]></
    > > > tag>
    > > > or something weirder- Hide quoted text -

    >
    > > > - Show quoted text -

    >
    > > I have, with the debuggin message within the code I can see exactly
    > > what is being transmitted. Unfortunately this is no much use sine  the
    > > data is base64 encoded and if decoded it´s still garbage since it´s a
    > > zip encoded stream.

    >
    > > Whether or not they are enclosing the information in CDATA, Im afraid
    > > they´re not. I will contact them see if I can get them to add that.

    >
    > > Thank you for your help.

    >
    > > Asis- Hide quoted text -

    >
    > > - Show quoted text -

    >
    > well CDATA isnt needed if it IS base64encoded as there will never be
    > any illegal xml characters. (< or &)
    > however if the stream you get when base64decoding is binary you do
    > need to know what it is, might it be gzipped rather than a zip. You
    > can test this by saving the binary within your server root somewhere
    > public as
    > test.txt.gz
    > and trying to retrieve it from a browser, the browser should
    > uncompress the stream and render the text. If it is just "corrupt"
    > meaning you cannot see any part of it using a hex editor then the
    > documentation from the developers of the service should say what
    > format it is, they really ought to provide some kind of "test" service
    > a known call and a known response, with a response already saved you
    > can calculate the md5 of both that way to compare.- Ocultar texto de la cita -
    >
    > - Mostrar texto de la cita -


    Ok so found the problem, the code is right, the only change that was
    needed was the way the string was "unzipped". The sting was compressed
    using gzip format so used gzuncompress() and voila, works. Thank you
    all for your help.
     
    , Dec 27, 2007
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. abcd
    Replies:
    7
    Views:
    548
    Edward Elliott
    May 1, 2006
  2. majj81
    Replies:
    0
    Views:
    354
    majj81
    May 31, 2006
  3. Chris Lambacher

    Re: Add file to zip, or replace file in zip

    Chris Lambacher, Jun 1, 2006, in forum: Python
    Replies:
    0
    Views:
    649
    Chris Lambacher
    Jun 1, 2006
  4. vicky
    Replies:
    3
    Views:
    2,032
    Brian Cryer
    Nov 22, 2010
  5. Saddergoat

    Recieve a file via HTTP POST to a webservice

    Saddergoat, Sep 5, 2003, in forum: ASP .Net Web Services
    Replies:
    0
    Views:
    163
    Saddergoat
    Sep 5, 2003
Loading...

Share This Page