httpWebRequest.AutomaticDecom pression不设置" Accept_Encoding:GZIP"头 [英] httpWebRequest.AutomaticDecompression does not set "Accept_Encoding: gzip" header

查看:152
本文介绍了httpWebRequest.AutomaticDecom pression不设置" Accept_Encoding:GZIP"头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是用我的.NET 3.0的应用程序的Web服务的参考,我试图建立gzip压缩解码。

I am using a web service reference in my .net 3.0 app and I'm trying to set up gzip decoding.

当我使用了SoapUI的答复是COM pressed用gzip,因为头接受编码:gzip,紧缩的要求设置。当我的.NET请求发送它没有这个头,这样服务器不COM pressing响应。

When I use SoapUI the responses are compressed with gzip because the the header 'Accept-Encoding: gzip,deflate' is set in the request. When my .net request is sent it does not have this header so the server is not compressing the response.

我发现这个链接的描述完全我想做的事情。我实现了code和与它正在对每个请求执行的调试验证,但它仍然是不添加接受编码:gzip。标题

I found this link which describes exactly what I want to do. I implemented the code and verified with the debugger that it was being executed on every request, but it is still not adding the 'Accept-Encoding:gzip' header.

接着我在从链接的类手动添加的报头

Next I added the header manually in the class from the link.

httpWebRequest.Headers.Add("Accept-Encoding", "gzip");

最后,我从服务器接收到一个COM pressed响应!但是,没有,现在我得到一个正常的XML例外,我敢pretty的肯定是因为响应不被DECOM $ P $即使pssed是通过使用类从链接设置以下。

Finally I received a compressed response from the server! But no, now I get an malformed xml exception which I'm pretty sure is because the response is not being decompressed even though the following is set by using the class from the link.

httpWebRequest.AutomaticDecompression = DecompressionMethods.GZip;;

我不明白什么错误。

I cannot understand what is going wrong.

推荐答案

好吧,我想出了一个解决我的问题。

Ok I figured out a solution to my problem.

由于我使用的Web引用您必须设置 EnableDecom pression = TRUE Web引用对象。

Since I am using a web reference you have to set EnableDecompression = true on the web reference object.

所以,解决的办法是这样的

So the solution is something like this

var client = new ReferredService
                 {
                     EnableDecompression = true
                 }

在这里ReferredService是Web引用名。

where ReferredService is the web reference name.

这篇关于httpWebRequest.AutomaticDecom pression不设置" Accept_Encoding:GZIP"头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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