我如何获得数据压缩 [英] How Can I Get Data Compression

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

问题描述

如何使用Web Api获取数据压缩



in c#



How can I get data Compressed using Web Api

in 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;
}


java脚本中的





in java script

$.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

推荐答案

.ajax({
type:' GEt'
url:URI,
contentType:' application / json; charset = utf-8'
data:ContentDataObject,
AcceptEncoding: gzip,deflate,sdch
dataType:' text'
接受:' application / json charset = utf-8'
})。done( function (ResultData){
.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(ResultData); }).error(function (jqXHR, textStatus, errorThrown) {


' #dvResult')。text(jqXHR.responseText || textStatus);
});
('#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


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

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