Non riesco a richiedere il servizio Web utilizzando https. Ricevo questo tipo di errore:Richiesta di servizio Web su SSL
An error occured : The certificate for this server is invalid. You might be connecting to a server that is pretending to be “SERVER_ADDRESS” which could put your confidential information at risk.
Non sto utilizzando NSUrlConnectionDelegate. Ecco il mio metodo:
- (void)sendRequestWithUrl:(NSURL*)url block:(void (^)(NSDictionary *dict, NSError *error)) block{
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
[request setHTTPMethod:@"POST"];
[[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]];
NSError* err = nil;
NSHTTPURLResponse* rsp = nil;
// Perform the request synchronously on this thread
NSData *rspData = [NSURLConnection sendSynchronousRequest:request returningResponse:&rsp error:&err];
if (rspData && err == nil) {
NSDictionary *result = [NSJSONSerialization JSONObjectWithData:rspData options:NSJSONReadingMutableLeaves error:&err];
if(result) {
block(result, err);
} else {
block(nil, err);
}
}else{
DLog(@"Requesting URL: %@ An error occured : %@",url,[err localizedDescription]);
block(nil, err);
}
}
Come posso risolvere questo problema?
Mi sembra che tu abbia problemi con un certificato autofirmato .. corretto? Vi consiglio di passare a una lib come [AFNetworking] (https://github.com/AFNetworking/AFNetworking/blob/master/README.md) o [MKNetworking] (https://github.com/MugunthKumar/MKNetworkKit /blob/master/README.mdown), che rende questo tipo di problemi più facile da gestire. Controllare: http://stackoverflow.com/questions/13077753/need-to-view-website-with-a-self-signed-certificate-and-http-authentication –
Inoltre, possibile duplicato di: http: // stackoverflow. it/questions/933331/how-to-use-nsurlconnection-to-connect-with-ssl-for-an-untrusted-cert –
Non voglio usare altre librerie. Anche in altre domande la soluzione è deprivata – Streetboy