我尝试使用以下代码发出 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];
但我得到以下回应。
错误 错误域=NSURLErrorDomain 代码=-1202 “此服务器的证书无效。您可能正在连接到伪装成“portkey.formspring.me”的服务器,这可能会使您的机密信息面临风险。” UserInfo=0x7564180 {NSLocalizedRecoverySuggestion=你想连接到服务器吗?, NSErrorFailingURLKey= https://portkey.formspring.me/login/, NSLocalizedDescription=此服务器的证书无效。您可能正在连接到一个伪装成“portkey.formspring.me”的服务器,这可能会使您的机密信息面临风险。NSUnderlyingError=0x7168a20“此服务器的证书无效。您可能正在连接到一个服务器冒充“portkey.formspring.me”,这可能会使您的机密信息面临风险。", NSURLErrorFailingURLPeerTrustErrorKey=}
谁能告诉我如何使用 NSURLConnection 发出 post 请求?
提前致谢。