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.
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.