1

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.

1
  • 1
    Have you tried something for it?? Commented Jul 2, 2012 at 11:18

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

3 Comments

It's fine. Instead of creating json object. How we create the XML object.
why you need to create xml object..?
can you please give me server side coding for this?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.