使用 deflatestream 在 .NET (Vb) 中使用压缩数据执行 HTTP Post
我从 VB.Net 客户端发布的数据很大,我想压缩。 我想做一个“POST”并且apache服务器支持mod_deflate。 我正在尝试将 DeflateStream 集成到我的帖子代码中,但似乎不起作用。
我可以使用标准代码发送不压缩的数据。
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()
但是我不确定如何使用 Deflate Stream 添加压缩。 我最好的猜测如下,但我认为它不起作用。
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()
问题。
- 我应该发送 压缩后的内容长度 流,如果是这样,我该如何得到它。
- 我应该写入数据流吗 或压缩?
- 你是这样使用的吗 DataStream 和 DeflateStram 一起?
- 在服务器端,考虑到 apache 应该自动处理膨胀,我该如何 知道它正在工作(到目前为止,我 知道我没有时间节省 所使用的两种方法之间的帖子 多于)。
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).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
此问题包含压缩请求的代码(隐式回答您的 Q1、Q2 和 Q3)。
Q4:使用嗅探器检查线路上发送的数据。 Fiddler2 是免费的,并且非常易于安装和使用。
链接问题的答案解释了为什么 mod_deflate 在请求压缩方面不会成为您的朋友。
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.