使用 deflatestream 在 .NET (Vb) 中使用压缩数据执行 HTTP Post

发布于 2024-08-22 00:13:10 字数 1465 浏览 13 评论 0原文

我从 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()

问题。

  1. 我应该发送 压缩后的内容长度 流,如果是这样,我该如何得到它。
  2. 我应该写入数据流吗 或压缩?
  3. 你是这样使用的吗 DataStream 和 DeflateStram 一起?
  4. 在服务器端,考虑到 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.

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

冷了相思 2024-08-29 00:13:10

此问题包含压缩请求的代码(隐式回答您的 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文