httpWebRequest.AutomaticDecompression does not set "Accept_Encoding: gzip" header
I am using a web service reference in my .net 3.0 app and I'm trying to set up gzip decoding.
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.
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");
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 = DecompressionM开发者_如何学JAVAethods.GZip;;
I cannot understand what is going wrong.
Ok I figured out a solution to my problem.
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
}
where ReferredService is the web reference name.
精彩评论