私はhttpsを使用してウェブサービスをリクエストするのに苦労しています。この種のエラーが発生します: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.
私はNSUrlConnectionDelegateを使用していません。ここに私の方法です:
- (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);
}
}
私はこの問題を解決できましたか?
自己署名証明書に問題があるようです。正しいのですか? [AFNetworking](https://github.com/AFNetworking/AFNetworking/blob/master/README.md)や[MKNetworking](https://github.com/MugunthKumar/MKNetworkKit)などのlibに変更することをお勧めします。 /blob/master/README.mdown)、これらの問題を扱いやすくします。チェック:http://stackoverflow.com/questions/13077753/need-to-view-website-with-a-self-signed-certificate-and-http-authentication –
また、可能な複製:http:// stackoverflow。 com/questions/933331/how-to-use-nsurl-connected-with-with-untrusted-cert –
私は他のライブラリを使いたくありません。また、他の質問解決策では省略されている – Streetboy