相关疑难解决方法(0)

如何使用NSURLConnection连接SSL以获取不受信任的证书?

我有以下简单的代码连接到SSL网页

NSMutableURLRequest *urlRequest=[NSMutableURLRequest requestWithURL:url];
[ NSURLConnection sendSynchronousRequest: urlRequest returningResponse: nil error: &error ];
Run Code Online (Sandbox Code Playgroud)

如果证书是自签名的,那么它会出错.Error Domain=NSURLErrorDomain Code=-1202 UserInfo=0xd29930 "untrusted server certificate".有没有办法将它设置为接受连接(就像在浏览器中你可以按接受)或绕过它的方法?

https objective-c ssl-certificate ios app-transport-security

299
推荐指数
9
解决办法
26万
查看次数

通过SSL HTTPS从iphone发送POST数据

海全,

在我的iphone项目中,我需要将用户名和密码传递给Web服务器,之前我使用GET方法传递数据并使用带有GET格式的URL(例如:localhost:8888/login?userName = admin&password = password)但是现在我需要将此作为POST数据发送,

任何人都可以帮我找到下面这段代码中的错误吗?

代码我试过..


NSString *post =[NSString stringWithFormat:@"userName=%@&password=%@",userName.text,password.text];

NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];

NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];

NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease];
[request setURL:[NSURL URLWithString:@"https://localhost:443/SSLLogin/login.php"]];
[request setHTTPMethod:@"POST"];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody:postData];

NSError *error;
NSURLResponse *response;
NSData *urlData=[NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
NSString *data=[[NSString alloc]initWithData:urlData encoding:NSUTF8StringEncoding];
NSLog(data);
Run Code Online (Sandbox Code Playgroud)

此页面将使用php echo返回成功或失败

iphone iphone-sdk-3.0

27
推荐指数
3
解决办法
6万
查看次数