Click here to Skip to main content
15,892,298 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How can I get data Compressed using Web Api

in c#

C#
[HttpGet]
[DeflateCompression]
public HttpResponseMessage Get()
{
    var response = new HttpResponseMessage();
    try
    {
        StringBuilder SBHtmltags = new StringBuilder();
       
        response.Content = new StringContent("test compression data");
        response.Content.Headers.ContentType = new MediaTypeHeaderValue("text/html");
    }
    catch (Exception ex)
    {
        return ControllerContext.Request.CreateResponse(HttpStatusCode.InternalServerError, ex.Message);
    }
    return response;
}

in java script

JavaScript
$.ajax({
                type: 'GEt',
                url: URI,
                contentType: 'application/json; charset=utf-8',
                data: ContentDataObject,
                AcceptEncoding: "gzip, deflate, sdch",
                dataType: 'text',
                accept: 'application/json charset=utf-8'
            }).done(function (ResultData) {
                $('#dvResult').text(ResultData);
            }).error(function (jqXHR, textStatus, errorThrown) {
                $('#dvResult').text(jqXHR.responseText || textStatus);
            });


but in browser network response still display as "test compression data" how can i make sure if data compressed or no
Posted

1 solution

You should use Fiddler to look at the HTTP headers. Take a look at this thread: http://stackoverflow.com/questions/897989/using-fiddler-to-check-iis-compression[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900