IOS中的HTTPS发布请求

Roc*_*cks 3 objective-c ios

我试图通过使用以下代码发出https发布请求.

NSURL *url = [NSURL URLWithString:@"https://portkey.formspring.me/login/"];

//initialize a request from url
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[url       standardizedURL]];

//set http method
[request setHTTPMethod:@"POST"];
//initialize a post data

NSDictionary *postDict = [NSDictionary dictionaryWithObjectsAndKeys:@"username", @"username",
                          @"password", @"password", nil];

NSError *error=nil;

NSData* jsonData = [NSJSONSerialization dataWithJSONObject:postDict
                                                   options:NSJSONWritingPrettyPrinted     error:&error];



[request setValue:@"application/x-www-form-urlencoded; charset=utf-8" forHTTPHeaderField:@"Content-Type"];

//set post data of request
[request setHTTPBody:jsonData];

//initialize a connection from request
NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];

//start the connection
[connection start];
Run Code Online (Sandbox Code Playgroud)

但是我得到了回应.

error Error Domain = NSURLErrorDomain Code = -1202"此服务器的证书无效.您可能正在连接到假装为"portkey.formspring.me"的服务器,这可能会使您的机密信息面临风险." UserInfo = 0x7564180 {NSLocalizedRecoverySuggestion =您是否要连接到服务器?,NSErrorFailingURLKey = https://portkey.formspring.me/login/,NSLocalizedDescription =此服务器的证书无效.您可能正在连接到假装>为"portkey.formspring.me"的服务器,这可能会使您的机密信息面临风险.,NSUnderlyingError = 0x7168a20"此服务器的证书无效.您可能正在连接到服务器假装是"portkey.formspring.me",可能会使您的机密信息面临风险.",NSURLErrorFailingURLPeerTrustErrorKey =}

谁能告诉我如何使用NSURLConnection发帖请求?

提前致谢.

lxt*_*lxt 7

您尝试连接的网站的证书不受信任(请尝试访问您在Chrome中发布的链接).

默认情况下,iOS不允许您连接到提供不受信任证书的站点.如果绝对必要,您可以绕过此检查 - 请参阅此问题:如何使用NSURLConnection连接SSL以获取不受信任的证书?

但是,实际修复相关证书会更好,更好.