How to send objecs from iPhone app to server app using XML?
I am creating an application in iPhone where communication with PHP server (using XML) is required.
I can receive data from the server and I am processing the XML file using the NSXML parser.
I haven't found too much documentation on sending data from iPhone to server (via XML).
Any idea, links and examples would be appreciated.
Best regards Alejandra
source to share
I am currently using XML-RPC to communicate with the server from the iPhone. There seem to be two implementations to choose from.
The most popular seems to be the WordPress iPhone app, but keep in mind that this is a GPL license:
http://iphone.trac.wordpress.org/browser/trunk/Classes/XMLRPC
I myself use this code which is licensed by MIT:
source to share
A quick and dirty synchronous REST implementation would look something like this:
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:@"http://yourserver.com/script"];
[request setHTTPMethod:@"POST"];
const char *bytes = [[NSString stringWithFormat:@"<?xml version=\"1.0\">\n<yourxml>%@</yourxml>", yourData] UTF8String];
[request setBody:[NSData dataWithBytes:bytes length:strlen(bytes)]];
NSURLResponse *response;
NSError *err;
NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&err];
It takes a few more steps to send this POST asynchronously. You can read about it in the docs for NSURLConnection and URL Loading .
source to share
it depends on the size of your data. but if it is simple data, I think you can use REST to publish or host the data to the server. http://en.wikipedia.org/wiki/Representational_State_Transfer
source to share