1

i wish to send some data as array from my iphone app to server

When i was posting single variables before i was sending the post as an NSString

NSString *post =[[NSString alloc] initWithFormat:@"userName=%@&accountID=%@&",
                                                  username,accId];

NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding  allowLossyConversion:YES];

NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];

NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease]; 
[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];

Now i wish to send an array of these usernames and accountIds, how do i send an NSArray in a POST and then in php on my server how can i retrieve it?

Thanks

4 Answers 4

1

use json, it's easier than messing with monstrous xml, json is quite easy on iphone with touchjson library and php supports json natively too

touchjson is at http://code.google.com/p/touchcode/wiki/TouchJSONHowTo

json is also smaller, so it saves some traffic when using over 3g

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

Comments

0

Create an XML and send it as POST data...

Comments

0

You might consider creating a xml file from the data first and then send it to your server. Creating and parsing XML is easy, take a look at libxml2

Comments

0

you could serialize the array and send it as a string :)

Comments

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.