Question

J'utilise l'API Geocoding Google V3 [1] à partir d'une application iOS mais je ne peux pas l'obtenir pour renvoyer une réponse GZIP.Le V2 était beaucoup plus léger mais avec V3, je reçois une réponse de ~ 20kb Json .. qui pourrait prendre un certain temps pour récupérer une mauvaise connexion GPRS, alors j'aimerais vraiment récupérer un résultat gzippé.

Est-ce que je me demande si je fais quelque chose de mal dans mon appel ou si leur API ne prend pas vraiment en charge Gzip ou dévier.Cela vous semble étrange.

C'est ce que je fais dans mon code:

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];

J'ai essayé avec seulement "gzip" et "dégonfler" aussi.Même résultat.

[1] http://code.google.com/apis/maps/Documentation / géocodage /

Était-ce utile?

La solution

I have no idea why, but it seems to have something to do with the User-Agent header. When I request the API page with Firefox (Mozilla/5.0 (Windows NT 6.1; WOW64; rv:10.0.2) Gecko/20100101 Firefox/10.0.2) I get a gzipped response. When I request the page with cURL (specifically asking for a compressed response), I get a plain response. However, if I override cURL's default agent to the Mozilla one, I do get a compressed response.

Autres conseils

At least for the GData APIs, you need to add a User-Agent header that contains the string gzip, see https://developers.google.com/gdata/faq#gzip. Hoping this would work with the Directions API service, I tried it and was able to get a gzip response.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top