海所有發送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