Sto facendo un servizio nella nostra azienda cliente. E cerco di ottenere alcune informazioni dal loro server tramite AFNetWorking (il nostro cliente incoraggia ad utilizzare AFNetWorking) Ho fatto un po 'di prova usando AFNetWorking, ed è lavoro. Ma quando io uso una delle nostre URL del cliente per ottenere i dati JSON, non è riuscito e questo è la descrizione di errore:Codice di errore -1011 quando utilizzo AFNetWorking
Error Domain=com.alamofire.networking.error Code=-1011
"Expected status code <NSIndexSet: 0x7e274f0>[number of indexes: 100 (in 1 ranges),
indexes: (200-299)], got 403" UserInfo=0x7b64040 {NSErrorFailingURLKey=<url_hidden_for_stackoverflow>,
NSLocalizedDescription=Expected status code <NSIndexSet: 0x7e274f0>[number of indexes: 100 (in 1 ranges), indexes: (200-299)], got 403}
cerco di trovare qualche soluzione, ma non posso ancora risolvere. C'è il mio codice:
NSURL *url = [NSURL URLWithString:@"http://example.com/"];
AFHTTPClient *httpClient = [[AFHTTPClient alloc] initWithBaseURL:url];
//[httpClient setDefaultHeader:@"Accept" value:@"text/json"];
//NSDictionary *params = [NSDictionary dictionaryWithObjectsAndKeys:CONST_KEY_REGISTER_UNIQUE_KEY, CONST_API_KEY_TEXT,nil];
NSMutableURLRequest *request = [httpClient requestWithMethod:@"POST" path:@"path/to/page.json" parameters:nil];
[httpClient release];
AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {
NSString *status = [JSON valueForKey:@"status"];
if ([status isEqualToString:@"OK"]) {
NSString *uniqueId = [JSON valueForKey:@"uniqueId"];
[UserSettings setWithKey:CONST_PROGRAM_UNIQUE_KEY value:uniqueId];
}
//NSString *message = [json valueForKey:@"message"];
//NSString *error = [json valueForKey:@"error"];
[[LoadingView instance] performSelectorOnMainThread:@selector(removeLoadingView) withObject:nil waitUntilDone:YES];
}
failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error) {
NSString *errorString = [error description];
[[LoadingView instance] performSelectorOnMainThread:@selector(removeLoadingView) withObject:nil waitUntilDone:YES];
}];
NSOperationQueue *queue = [[[NSOperationQueue alloc] init] autorelease];
[queue addOperation:operation];
Grazie per la lettura, e qualsiasi aiuto o risposta sarà molto apprezzato.
EDIT: Come ha detto DarkDust: il server nega il mio accesso. Ma posso ottenere i dati dal server connessione di base: Ecco il codice per ottenere:
NSURL *url = [NSURL URLWithString:@"http://example.com/path/to/page.json"];
NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringLocalAndRemoteCacheData timeoutInterval:CONST_CONNECTION_TIMEOUT];
rssConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
[self performSelectorOnMainThread:@selector(downloadStarted) withObject:nil waitUntilDone:NO];
if (rssConnection != nil) {
do {
[[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]];
} while (!done);
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
// I can get text here, but it is not JSON format
NSString *content = [NSString stringWithUTF8String:[data bytes]];
}
mi chiedo perché rssConnection può ottenere il testo JSON e AFHTTPClient non può?
Pensi davvero che sia una buona idea pubblicare i dettagli interni/privati del tuo cliente senza offuscare? – DarkDust
Questa è solo una pagina di prova, non una pagina privata. Ci saranno più cambiamenti prima che io possa finire. E il futuro, ci sarà bisogno di una chiave API per l'accesso e, naturalmente, lo nascondo. – magichero
Ancora, tutti ora possono vedere chi è il tuo cliente. Il tuo cliente potrebbe non essere molto contento di questo. – DarkDust