unable to get data from iphone application
Posted
by user317192
on Stack Overflow
See other posts from Stack Overflow
or by user317192
Published on 2010-04-15T06:49:19Z
Indexed on
2010/04/15
6:53 UTC
Read the original article
Hit count: 302
iphone
Hi, I have made a php web services that takes the username and password from iPhone application and saves the data in the users table.
I call that web service from my button touchup event like this:
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 am getting nothing from Iphone side into the web service and I am unable to understand why this is happening. Although i debugged and found that everything is fine at the iphone application level but the call to the web service doesn't works as expected......
Please suggest.....
Thanks Ashish
© Stack Overflow or respective owner