I want to post data through json webservicesmy on button click Action code is:
-(IBAction)login:(id)sender {
NSString *newurlString = [NSString StringWithFormat:@"{\"name\":\"asit\",\"email\":\"m.kulkarni@easternenterprise.com\",\"businessType\":\"1\",\"score\":30}"];
NSString * url = @"http://www.nieuwe-dag.nl/mobile_be/public/?action=saveScore";
NSData *postData = [newurlString dataUsingEncoding:NSUTF8StringEncoding allowLossyConversion:YES];
NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];
NSLog(@"urlString::%@",newurlString);
NSLog(@"postLength::%@",postLength);
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:url] cachePolicy:NSURLCacheStorageNotAllowed timeoutInterval:300];
[request setHTTPMethod:@"POST"];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody:postData];
NSURLConnection *theConnection =[[NSURLConnection alloc] initWithRequest:request delegate:self];
if( theConnection ) {
webData = [[NSMutableData data] retain];
}
else {
NSLog(@"theConnection is NULL");
}
}
And response on console is:
[Session started at 2011-07-25 12:36:48 +0530.] 2011-07-25 12:36:48.860 DepartmentalStoreAdmin[2490:207] Could not load the "header.png" image referenced from a nib in the bundle with identifier "com.easternenterprise.dag" 2011-07-25 12:36:48.864 DepartmentalStoreAdmin[2490:207] Could not load the "leher.png" image referenced from a nib in the bundle with identifier "com.easternenterprise.dag" 2011-07-25 12:36:50.708 DepartmentalStoreAdmin[2490:207] urlString::{"name":"asit","email":"m.kulkarni@easternenterprise.com","businessType":"1","score":30} 2011-07-25 12:36:50.709 DepartmentalStoreAdmin[2490:207] postLength::88 2011-07-25 12:36:52.376 DepartmentalStoreAdmin[2490:207] DONE. Received Bytes: 52 2011-07-25 12:36:52.377 DepartmentalStoreAdmin[2490:207]
THEXML {"result":"ERROR","errors":["Name cannot be empty"]}
I don't have any idea why it is not post.