Failed to get data from iphone application

I made php web services that take username and password from iPhone application and save data in user table.

I call this web service from the touchup event for this button as follows:

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!"); 

I don’t get anything from Iphone in the web service and I can’t understand why this is happening. Although I debugged and found that at the iphone level everything is fine, but the web service call does not work as expected ......

Please suggest .....

Thanks Ashish

0
source share
1 answer

Try registering localizedFailureReason or localizedRecoverySuggestion or localizedRecoveryOptions of the "error" property if the error is not zero. This may indicate the cause of the failure when sending a request or receiving a response.

+1
source

Source: https://habr.com/ru/post/1307000/


All Articles