views:

180

answers:

1

The data that I am posting from a VB.Net client is large and I want to compress. I want to do a "POST" and the apache server supports mod_deflate. I am trying to integrate DeflateStream into my post code, however does not seem to be working.

I can send the data without compression using the standard code.

    request.ContentType = "application/x-www-form-urlencoded"

    Dim dataStream As Stream = request.GetRequestStream()
    Dim byteArray As Byte() = Encoding.UTF8.GetBytes(strEncodedXML)
    request.ContentType = "application/x-www-form-urlencoded"
    request.ContentLength = byteArray.Length
    dataStream.Write(byteArray, 0, byteArray.Length)
    dataStream.Close()
    Dim response As WebResponse = request.GetResponse()

However I am not sure how to add the compression using the Deflate Stream. My best guess is the following, however I do not think it is working.

    request.Headers.Add("Content-Encoding", "deflate")
    request.ContentType = "application/x-www-form-urlencoded"

    Dim dataStream As Stream = request.GetRequestStream()
    Dim byteArray As Byte() = Encoding.UTF8.GetBytes(strEncodedXML)
    Dim compress As New DeflateStream(dataStream, CompressionMode.Compress, True)
    request.ContentType = "application/x-www-form-urlencoded"
    request.ContentLength = byteArray.Length
    dataStream.Write(byteArray, 0, byteArray.Length)
    dataStream.Close()
    Dim response As WebResponse = request.GetResponse()

Questions.

  1. Should I be sending the ContentLength of the Compressed Stream, if so, how do I get that.
  2. Should I be writing to the datastream or compress?
  3. Is this how you use DataStream and DeflateStram together?
  4. On the server side, considering that apache is automatically supposed to be handling the inflating, how do I know that it is working (so far, I know there is no times savings on my posts between the two methods used above).
A: 

This question contains code that zips the request (which implicitely answers your Q1,Q2 and Q3).

Q4: Use a sniffer to check the data sent on the wire. Fiddler2 is free and super easy to install and use.

Answers to the linked question explain why mod_deflate is not going to be your friend regarding compression of the request.

Serge - appTranslator