Compress a HttpWebRequest using gzip

后端 未结 2 1014
面向向阳花
面向向阳花 2021-01-24 02:15

I am developing a .NET 4.0 Console Application to serve as a SOAP Web Service client which will send data (POST) through to a third-party. I have no c

2条回答
  •  执念已碎
    2021-01-24 03:15

    Use the following in place of your current code to send the request.

    using (Stream stream = request.GetRequestStream())
    using (GZipStream gz = new GZipStream(stream, CompressionMode.Compress, false))
    {
        soapXml.Save(gz);
    }
    

    Edit: Might need to use "new GZipStream(stream, CompressionMode.Compress, true)". Can't say for certain how that constructor parameter will affect the web request stream.

提交回复
热议问题