ASIHTTPRequest gzip decompression



我目前正试图解压缩一些数据,我已经进入ASIHTTPRequest包装器。但不确定需要做什么。我已经阅读了文档,但是它没有给出很多细节。

这是我目前所拥有的://. h

//Compression stuff
BOOL dataWasCompressed;
NSData *compressedResponse;
NSData *uncompressedData;
NSString *response;

//……

//m

//Compression Test
- (IBAction)sendHttpsRequest
{
    //Start HUD
        [SVProgressHUD showWithMaskType:SVProgressHUDMaskTypeBlack];
        [SVProgressHUD setStatus:@"loading..."];
        NSURL *url = [NSURL URLWithString:@"http://127.0.0.1:8888/testConnection/ClientDataSet.xml.compressed"];
        ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
        // YES is the default, you can turn off gzip compression by setting this to NO
        [request setAllowCompressedResponse:YES];
        [request startSynchronous];
        dataWasCompressed = [request isResponseCompressed]; // Was the response gzip compressed?
        compressedResponse = [request rawResponseData]; // Compressed data
        uncompressedData = [request responseData]; // Uncompressed data
        response = [request responseString]; // Uncompressed data as a string

    NSLog(@"compressed? %@", dataWasCompressed);
    NSLog(@"compressed Response = %@", compressedResponse);
    NSLog(@"uncompressed Data = %@", uncompressedData);
    NSLog(@"response = %@", response);
}
- (void)requestFinished:(ASIHTTPRequest *)request
{   
    self.hudCheck = YES;
    responseString = [request responseString]; //Pass requested text from server over to NSString 
    NSLog(@"Response String = %@", responseString);
    //removies the SVProgressHUD
    [NSTimer scheduledTimerWithTimeInterval:0.25 target:self selector:@selector(stopAnimating) userInfo:nil repeats:NO];
}

反应是这样的

2011-12-08 10:33:50.845 connectionTest[2049:207] compressed? (null)
2011-12-08 10:33:50.846 connectionTest[2049:207] compressed Response = <789c7d93 6d6f8230 1080ffca a53f6060 877b4900 d3292a99 4e036c7e 5ceaac8e 0d8b834e c55fbfc2 869238af 5fdaf4b9 bb5e9fb4 7667bf4e 602bb23c 4ea5435a 5726815c 71b9e049 2a85430a 91938e0b 60f758c4 a6acfbe8 45f05247 531dedda 632f6225 75edbeef 8d7ae1df 0c5ca94c f2b52ef2 90a689e0 b21f8b64 4160594e aad86830 ff05c438 cff1a512 2b919de7 c4d67fe1 a1ca62b9 3a8fceab 7d0233bf 170d1dd2 36cd32db a83b9db2 808d43e8 0ed9d3c0 7b1d4d06 5a019850 1d619c2e 164c66c7 0504e92e 545ce9e2 1681e6d5 1c1205cf 1e8166eb 5a92590f 028d2ef5 41269fbf 2dc472f5 1e7f7c26 6b996ebe b25c7d6f 77fbe2d0 6a218c22 ec1a6116 c2da08bb 41d82dc2 ee10767f 9951c40b 45bc50c4 0b45bc50 c40b45bc 50c40bbd e0a57a57 c7d7649c 3e95fb03 b0ff49b1>
2011-12-08 10:33:50.846 connectionTest[2049:207] uncompressed Data = <789c7d93 6d6f8230 1080ffca a53f6060 877b4900 d3292a99 4e036c7e 5ceaac8e 0d8b834e c55fbfc2 869238af 5fdaf4b9 bb5e9fb4 7667bf4e 602bb23c 4ea5435a 5726815c 71b9e049 2a85430a 91938e0b 60f758c4 a6acfbe8 45f05247 531dedda 632f6225 75edbeef 8d7ae1df 0c5ca94c f2b52ef2 90a689e0 b21f8b64 4160594e aad86830 ff05c438 cff1a512 2b919de7 c4d67fe1 a1ca62b9 3a8fceab 7d0233bf 170d1dd2 36cd32db a83b9db2 808d43e8 0ed9d3c0 7b1d4d06 5a019850 1d619c2e 164c66c7 0504e92e 545ce9e2 1681e6d5 1c1205cf 1e8166eb 5a92590f 028d2ef5 41269fbf 2dc472f5 1e7f7c26 6b996ebe b25c7d6f 77fbe2d0 6a218c22 ec1a6116 c2da08bb 41d82dc2 ee10767f 9951c40b 45bc50c4 0b45bc50 c40b45bc 50c40bbd e0a57a57 c7d7649c 3e95fb03 b0ff49b1>
2011-12-08 10:33:50.847 connectionTest[2049:207] response = x}mo0ÿÊ¥?``{I

所以我很确定布尔值没有被设置为它给我一个空值。你们能看出我做错了什么吗?如果设置bool,数据是否只传递给requestFinished ?还是有更深层次的问题?

ASIHTTPRequest只有在服务器将内容编码的HTTP响应头设置为"gzip"时才知道下载是否被压缩。

你的测试/web服务器正在这样做吗?

同样,在代码中,将NSLog行更改为:

NSLog(@"compressed? %@", dataWasCompressed ? @"YES" : @"NO" );

最新更新