海所有发送POST数据,从iphone通过SSL HTTPS
在我的iPhone项目,我需要的用户名和密码传递到Web服务器,以前我通过使用GET方法的数据和使用GET格式的URL (如:本地主机:8888 /登录用户名=管理员密码& =密码?),但现在我需要发送这是一个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);
这个页面将返回成功或失败的使用PHP呼应
如何不工作的代码? – 2009-10-15 10:00:59
是的,它不起作用 – 2009-10-15 10:11:56
我的意思是,它究竟是如何失败?什么是错误?它崩溃了吗?你在哪里看到问题,在服务器或客户端代码中? – 2009-10-15 10:37:32