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-urlencod开发者_如何学Ced"
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).
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.
精彩评论