如何使用gzip压缩获取webresponse [英] How to get webresponse using gzip compression

查看:164
本文介绍了如何使用gzip压缩获取webresponse的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已尝试使用以下代码从服务器获取web响应。

I have tried the code below to get webresponse from the server.

string soap = "my xml file";
HttpWebRequest req =(HttpWebRequest)WebRequest.Create("http://212.170.239.71/appservices/http/FrontendService");
req.ContentType = "text/xml;charset=utf-8";
req.Accept = "text/xml";
req.Method = "POST";
using (Stream stm = req.GetRequestStream())
{
    using (StreamWriter stmw = new StreamWriter(stm))
    {
        stmw.Write(soap);
    }
}

WebResponse response = req.GetResponse();
XmlDocument xDoc = new XmlDocument();
XmlTextReader myXMLReader = null;
myXMLReader = new XmlTextReader(response.GetResponseStream());
string asdfgh = myXMLReader.ReadOuterXml();
xDoc.Load(myXMLReader);



但现在webservice的代理告诉我使用Gzip压缩来发送请求并收到响应。 />


我只是无能为力地使用Gzip压缩。

请帮助我


But now the agents of the webservice told me to use Gzip compression to send the request and recieve the response.

I am just clueless to use Gzip compression.
Please help me

推荐答案

你可以试试这个。



You can try this.

using (Stream stm = req.GetRequestStream())
{
  using (GZipStream compressionStream = new GZipStream(stm, CompressionMode.Compress))
  {
    byte[] input = ASCIIEncoding.ASCII.GetBytes(soap);
    compressionStream.Write(input, 0, input.Length);
  }
}





此处可以找到更多信息 http://msdn.microsoft.com/en-us/library/system.io .compression.gzipstream.write(v = vs.110).aspx [ ^ ]


这篇关于如何使用gzip压缩获取webresponse的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆