Hi,
Simple question, I want to receive compressed data from a server using
AJAX.
At the client I make an xmlHttpRequest. Next I want to set the
accept-header to Gzip, but I keep getting errors on that under opera.
At server-side I first check the accept-header, if it supports gzip I
make a ZIP-stream and set the content-encoding to gzip. Normaly I would
think the browser itself can handle it and give the uncompressed
response.
Clientcode (javascript):
xmlHttp = =new XMLHttpRequest( );
xmlHttp.onready statechange = stateChange;
//don't work
xmlHttp.setRequ estHeader("Acce pt-Encoding", "gzip");
xmlHttp.open("G ET", "servlet", false);
xmlHttp.send(nu ll);
function stateChange() {
if (xmlHttp.readyS tate==4 || xmlHttp.readySt ate=="complete" ) {
var response = xmlHttp.respons eText;
alert(response) ;
var uncompressedRes ponse = response;
document.getEle mentById("code" ).innerHTML =
"<p>"+uncompres sedResponse+"</p>";
}
}
Servercode (servlet):
public void doGet(HttpServl etRequest request, HttpServletResp onse
response) {
String text = "sometext";
response.setCon tentType("text/html");
OutputStream out = null;
String encoding = request.getHead er("Accept-Encoding");
if (encoding != null && encoding.indexO f("gzip") != -1)
{
response.setHea der("Content-Encoding" , "gzip");
out = new GZIPOutputStrea m(response.getO utputStream());
}
else if (encoding != null && encoding.indexO f("compress") != -1)
{
response.setHea der("Content-Encoding" , "compress") ;
out = new ZipOutputStream (response.getOu tputStream());
}
else
{
out = response.getOut putStream();
System.out.prin tln("gewone uitvoerstroom") ;
}
byte[] b = text.getBytes() ;
out.write(b);
}
What am I doing wrong?
thx in advance 1 5912
stroumf escreveu:
At the client I make an xmlHttpRequest. Next I want to set the
accept-header to Gzip, but I keep getting errors on that under opera.
At server-side I first check the accept-header, if it supports gzip I
make a ZIP-stream and set the content-encoding to gzip. Normaly I would
think the browser itself can handle it and give the uncompressed
response.
Well, here it's working fine on Opera. My web server compression is
turned on and for the XHR request I just outputed the received headers,
the gzip was there and as I could read, the text was decompressed by the
browser.
Servercode (servlet):
If you think the problem is within your Java code, post it in a Java
newsgroup, you'll get better answers :]
--
Jonas Raoni Soares Silva http://www.jsfromhell.com This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Dennis Hotson |
last post by:
Hi,
I'm trying to write a function that adds a file-like-object to a
compressed tarfile... eg ".tar.gz" or ".tar.bz2"
I've had a look at the tarfile module but the append mode doesn't support
compressed tarfiles... :(
Any thoughts on what I can do to get around this?
|
by: Norman Barker |
last post by:
Hi,
I have spent most of the day on this so any help would be appreciated.
I have set up mod_deflate in Apache so that any input marked
content-type gzip from the client is automatically decompressed before
being forwarded on to the server-side java servlet.
The idea is that I compress a file on the client write it to the stream
and then it reaches the servlet decompressed through Apache. At the
|
by: BW |
last post by:
Sorted my problem.
Issue - retrieve Base64 encoded Zlib compressed XML stream.
The compressed XML stream was compressed using Zlib on a Java
platform.
Resolution. (VB.NET)
1) Retrieve XML stream using webresponse class
|
by: PerryG |
last post by:
We have a .NET 1.1 client which is sending a gzipped soap request using
HttpWebRequest to an Apache server. The Apache server is using a the
'mod_deflate' server to decompress the incoming message, and to also compress
the response (GZIP).
The mod_deflate filter requires the 'Content-Length' header contained within
the incoming request to specify the number of UNCOMPRESSED bytes being sent
and not the actual bytes of the body of the...
|
by: Vladimir Nesterovsky |
last post by:
Hello,
I'm having a trouble with a Shell.Folder object when I'm trying to use it
from a C++ application, but at the same time, the same object works fine
from within html script.
The effect is that, I cannot put data into a compressed folder in C++, in
spite of the fact that all operations succeed.
Note: all this have to work under XP and above, because of integrated
| |
by: Leonardo Francalanci |
last post by:
With mysql I know how much space a row will take, based on the datatype
of it columns. I also (approximately) know the size of indexes.
Is there a way to know that in postgresql?
Is there a way to pack (compress) data, as with myisampack for mysql?
Thank you
|
by: robert |
last post by:
Hello,
I want to put (incrementally) changed/new files from a big file tree
"directly,compressed and password-only-encrypted" to a remote backup
server incrementally via FTP,SFTP or DAV.... At best within a closed
algorithm inside Python without extra shell tools.
(The method should work with any protocol which allows somehow read,
write & seek to a remote file.)
On the server and the transmission line there should never be...
|
by: Pat B |
last post by:
Hi, I'm writing my own implementation of the Gnutella P2P protocol
using C#. I have implemented it using BeginReceive and EndReceive
calls so as not to block when waiting for data from the supernode.
Everything I have written works fine sending and receiving
uncompressed data. But now I want to implement compression using the
deflate algorithm as the Gnutella protocol accepts:
Accept-Encoding: deflate
Content-Encoding: deflate
in the...
|
by: Author |
last post by:
I am exploring the DeflateStream class as a practice. I thought it is
fun to compress a text file and write it to a disk file. So I created
the following method. If you don't bother reading the small code
snippet, here is a summary of what I did:
1. Read the text content into a buffer through FileStream.Read.
2. Create a DeflateStream by wrapping up a MemoryStream.
3. Write the compressed data into the underline stream (the...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |