I am new to iPhone Programming.
I am have one NSMutableArray
i want to POST
that array to server's php
file and update my server's xml
file.
Thanks in advance.
I am new to iPhone Programming.
I am have one NSMutableArray
i want to POST
that array to server's php
file and update my server's xml
file.
Thanks in advance.
May you need this code ..
declare a reference of NSURLConnection *postConnection in .h and make it property and synthesize in .m file...
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:@"yourPhpUrl.php"]];
[request setHTTPMethod:@"POST"];
NSMutableDictionary *jsonDict = [[NSMutableDictionary alloc] init];
[jsonDict setValue:yourArray forKey:@"userName"];
NSLog(@"JSON Dict: %@",jsonDict);//Check your array here...
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:jsonDict options:kNilOptions error:nil];
NSString *jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
NSLog(@"JSON String: %@",jsonString); //Check your post String here...
[request setValue:@"application/json" forHTTPHeaderField:@"Accept"];
[request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
[request setValue:@"json" forHTTPHeaderField:@"Data-Type"];
[request setValue:[NSString stringWithFormat:@"%d", [jsonData length]] forHTTPHeaderField:@"Content-Length"];
[request setHTTPBody: jsonData];
self.postConnection = [[NSURLConnection alloc] initWithRequest:request delegate:self startImmediately:true];
may this will help you