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.
- Should I be sending the ContentLength of the Compressed Stream, if so, how do I get that.
- Should I be writing to the datastream or compress?
- Is this how you use DataStream and DeflateStram together?
- 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).