作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我目前正在尝试解压缩 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 值没有被设置,因为它给了我一个空值。你们能看出我做错了什么吗?如果设置了 bool,数据是否仅传递给 requestFinished?还是这里有更深层次的问题?
最佳答案
ASIHTTPRequest 仅在由将内容编码 HTTP 响应 header 设置为“gzip”的服务器提供下载服务时才知道下载是否已压缩。
您的测试/网络服务器正在执行此操作吗?
此外,在您的代码中,将 NSLog 行更改为:
NSLog(@"compressed? %@", dataWasCompressed ? @"YES" : @"NO" );
关于iphone - ASIHTTPRequest gzip 解压,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8423030/
我是一名优秀的程序员,十分优秀!