无法从iPhone应用程序获取数据

问题描述:

我已经做了一个PHP Web服务,它从iPhone应用程序获取用户名和密码并将数据保存在用户表中。无法从iPhone应用程序获取数据

我调用Web服务从我的按钮触上事件是这样的:

NSLog(userName.text); 
NSLog(password.text); 

NSString * dataTOB=[userName.text stringByAppendingString:password.text]; 

NSLog(dataTOB); 

NSData * postData=[dataTOB dataUsingEncoding:NSUTF8StringEncoding allowLossyConversion:YES]; 

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

NSLog(postLength); 

NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease]; 

NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"http://localhost:8888/write.php"]]; 

[request setURL:url]; 
[request setHTTPMethod:@"POST"]; 
[request setValue:postLength forHTTPHeaderField:@"Content-Length"]; 
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"]; 
[request setHTTPBody:postData]; 

NSURLResponse *response; 
NSError *error; 

[NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error]; 

if(error==nil)  
    NSLog(@"Error is nil"); 
else 
    NSLog(@"Error is not nil"); 
NSLog(@"success!"); 

我正在从iPhone侧面什么到Web服务,我无法理解为什么这种情况正在发生。虽然我调试,发现一切都在iPhone应用水平,但并没有按预期工作调用Web服务细......

请建议.....

感谢 Ashish

尝试记录localizedFailureReason或localizedRecoverySuggestion或localizedRecoveryOptions属性的'错误',如果错误不为零。如果在发送请求或接收响应时遇到故障,这可能会给出原因。