XML HTTP response gzip(gunzip)

1,037 views
Skip to first unread message

farzades

unread,
Jun 10, 2011, 7:44:32 AM6/10/11
to phon...@googlegroups.com
Hi

using a code like below , i sending a request (xmlhtttp request) to a server to call a soap web service !! The problem is the response to this request is gzip so ,
using PhoneGap how to unzip the content of a xmlHttpResponse that is encoded by gzip ??
I didn't find any javascript library for gunzip !!

    xmlhttp.onreadystatechange = processRequest;
    xmlhttp.open("POST", Url ,true);

    xmlhttp.setRequestHeader("POST" , Url);   
    xmlhttp.setRequestHeader("Content-Type",  "text/xml; charset=utf-8");
    xmlhttp.setRequestHeader("Accept-Encoding", "gzip");
    xmlhttp.setRequestHeader("SOAPAction", soapActionUrl);   

    xmlhttp.send(xmlInput);


Thank you


Robert Fletcher

unread,
Jun 10, 2011, 1:20:32 PM6/10/11
to phon...@googlegroups.com

You might consider using confusion to download the gzip files to your server then use cf to extract that gzip file.

Then use your code you to read the file locally.

On Jun 10, 2011 7:44 AM, "farzades" <f.eska...@gmail.com> wrote:
> Hi
>
> using a code like below , i sending a request (xmlhtttp request) to a server
> to call a soap web service !! The problem is the response to this request is
> gzip so ,
> using PhoneGap how to unzip the content of a xmlHttpResponse that is encoded
> by gzip ??
> I didn't find any javascript library for gunzip !!
>
> *xmlhttp.onreadystatechange = processRequest;

> xmlhttp.open("POST", Url ,true);
>
> xmlhttp.setRequestHeader("POST" , Url);
> xmlhttp.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
> xmlhttp.setRequestHeader("Accept-Encoding", "gzip");
> xmlhttp.setRequestHeader("SOAPAction", soapActionUrl);
>
> xmlhttp.send(xmlInput);*
>
> Thank you
>
>
> --
> You received this message because you are subscribed to the Google
> Groups "phonegap" group.
> To post to this group, send email to phon...@googlegroups.com
> To unsubscribe from this group, send email to
> phonegap+u...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/phonegap?hl=en?hl=en
>
> For more info on PhoneGap or to download the code go to www.phonegap.com

farzades

unread,
Jun 10, 2011, 6:14:13 PM6/10/11
to phon...@googlegroups.com
Thank you for your reply ,

Download the gzip file to my server ?? What do you mean ??
I'm using a web service to get some info to load it platform independently on the phone using phoneGap.

If there is no solution in javascript or phoneGap for this ,i prefer to write it by java , then make it available to javascript and phoneGap , but i should do this for each platform .

Robert Fletcher

unread,
Jun 10, 2011, 7:43:28 PM6/10/11
to phon...@googlegroups.com
sorry i typed that on my phone so it didn't quite come out the way i had hoped. haha.

I meant to say download the file using a server side language like coldfusion (the auto correct made it say confusion).  I recently wrote the scripts to download a gzip file, extract the gzip file and then i had to ftp the files to the database server to be bulk imported.

It was not too difficult to read the files and a coldfusion component i blogged about on my website made extracting it a one-line piece of code.


For you i was suggesting download the files and then you could read it with js once its on your server, but you'll probably need something other then phonegap to extract the gzip file. 

I do not know if you can do that with javascript, but my guess is probably not...So, CF will really help you out here.

But keep in mind you won't be able to deploy the coldfusion files to phonegap so you have to keep everything in your app as html / css/ js.



Gunesh Raj

unread,
Jun 11, 2011, 4:18:34 AM6/11/11
to phonegap
Hi,

Perhaps removing this line in your call would help:

xmlhttp.setRequestHeader("Accept-Encoding", "gzip");

The reason is that you tell the Web Server that you CAN ACCEPT GZIP
and not other formats,

If you need it in any other format, you could add it in there, please
check on HTTP 1.1 Accept-Encoding

Hope it helps

Gunesh



On Jun 10, 7:44 am, farzades <f.eskandan...@gmail.com> wrote:
> Hi
>
> using a code like below , i sending a request (xmlhtttp request) to a server
> to call a soap web service !! The problem is the response to this request is
> gzip so ,
> using PhoneGap how to unzip the content of a xmlHttpResponse that is encoded
> by gzip ??
> I didn't find any javascript library for gunzip !!
>
>     *xmlhttp.onreadystatechange = processRequest;
>     xmlhttp.open("POST", Url ,true);
>
>     xmlhttp.setRequestHeader("POST" , Url);    
>     xmlhttp.setRequestHeader("Content-Type",  "text/xml; charset=utf-8");
>     xmlhttp.setRequestHeader("Accept-Encoding", "gzip");
>     xmlhttp.setRequestHeader("SOAPAction", soapActionUrl);    
>
>     xmlhttp.send(xmlInput);*
>
> Thank you

farzades

unread,
Jun 11, 2011, 1:42:25 PM6/11/11
to phon...@googlegroups.com
this is not a solution I'm looking for , but thanks !!

farzades

unread,
Jun 11, 2011, 1:46:43 PM6/11/11
to phon...@googlegroups.com
Thank you Gunesh ,
It seems that the server is only present this type of encoding (gzip) .

I removed the line of code you mentioned ,
also checked with this code :

xmlhttp.setRequestHeader("Accept-Encoding", "compress;q=0, gzip;q=0");


but nothing changed , and the response looks the same .

Gunesh Raj

unread,
Jun 12, 2011, 12:21:08 PM6/12/11
to phonegap
Hi,

Did you try some of these values in Accept-Encoding ?

1) text/html;level=1
2) text/html
3) text/plain

You need to explicitly force the headers to use this values:

eg:

xmlhttp.setRequestHeader("Accept-Encoding", "text/html");*

You could try testing it using a http tester from your desktop.

Most of the time, any soap server should comply to that as gzip
encoding is a layer above text/html

If it still does not work, Im afraid that you need to create a phone
gap plugin to handle this. Its not very hard to do this.

There are also IFrame / Cross Scripting methods that would
automatically convert GZIP to its native format & Since PhoneGap is
essentially a WebView, its worth a try

Good Luck

Gunesh

On Jun 12, 1:46 am, farzades <f.eskandan...@gmail.com> wrote:
> Thank you Gunesh ,
> It seems that the server is only present this type of encoding (gzip) .
>
> I removed the line of code you mentioned ,
> also checked with this code : *
>
> xmlhttp.setRequestHeader("Accept-Encoding", "compress;q=0, gzip;q=0");*
Reply all
Reply to author
Forward
0 new messages