Question

I want to insert many data to a mysql database, only text of course.

I'm currently doing via post, for example insertUser.php?user=asd&pass=asdas&email=asdasd and it will give me a response if it was ok or not, but now I'm trying to upload a giant amount of data like insertData.php?xml=string&userid=2 and the response it's big too and sometimes it will take long time because it's for mobile phone applications mostly using 3g (android & iOS), so which will be more efficient, still doing post connections or a direct mysql connection?

Thanks.

Was it helpful?

Solution

Check the answer below

xmlbody = (NSString *)CFURLCreateStringByAddingPercentEscapes(
                                                                        NULL,
                                                                            (CFStringRef)xmlbody,
                                                                            NULL,
                                                                            (CFStringRef)@"!*'\"();:@&=+$,/?%#[]% ",
                                                                            kCFStringEncodingUTF8 );

NSMutableString *entirexmlbody=[[NSMutableString alloc]init ];
[entirexmlbody appendString:@"xml="];
[entirexmlbody appendString:xmlbody];

NSLog(@"posting XML Body after encoding--%@\n",xmlbody);

NSData *postData = [entirexmlbody dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
NSString *postLength = [NSString stringWithFormat:@"%d",[postData length]];
NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease];
[request setURL:[NSURL URLWithString:posturl]];

[request setHTTPMethod:@"POST"];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody:postData];
NSURLConnection *conn=[[[NSURLConnection alloc] initWithRequest:request delegate:self] autorelease];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top