Domanda

Sto usando l'API Geocoding di Google V3 [1] da un'applicazione iOS ma non riesce a restituire una risposta gzip.Il V2 era molto più leggero ma con V3 sto ottenendo una risposta JSON di ~ 20kb .. che potrebbe richiedere del tempo per recuperare una cattiva connessione GPRS, quindi vorrei davvero ottenere un risultato Gzipped.

Mi chiedo se sto facendo qualcosa di sbagliato nella mia chiamata o se la loro API non supporta Gzip o deflate.Sembra strano per me.

Questo è quello che sto facendo nel mio codice:

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

Ho provato anche con solo "gzip" e anche "deflate".Stesso risultato.

[1] http://code.google.com/apis/maps/Documentazione / Geocoding /

È stato utile?

Soluzione

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.

Altri suggerimenti

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.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top