我正在使用来自 iOS 应用程序的 Google Geocoding API v3[1],但无法让它返回 gzip 响应。v2 更轻量级,但在 v3 中,我得到了大约 20kb JSON 响应.. 在 GPRS 连接不良时可能需要一些时间来检索,所以我真的很想得到一个 gzip 压缩的结果。
我想知道我的通话中是否做错了什么,或者他们的 API 是否真的不支持 gzip 或 deflate。这对我来说听起来很奇怪。
这是我在我的代码中所做的:
NSURL *url = [NSURL URLWithString:@"http://maps.googleapis.com/maps/api/geocode/json?latlng=55,12&sensor=true"];
NSMutableURLRequest *req = [[NSMutableURLRequest alloc] initWithURL:url];
[req setValue:@"gzip,deflate" forHTTPHeaderField:@"Accept-Encoding"];
NSURLConnection *c = [[NSURLConnection alloc]
initWithRequest:req delegate:self startImmediately:YES];
我也只尝试过“gzip”和“deflate”。结果相同。
[1] http://code.google.com/apis/maps/documentation/geocoding/