哪种更有效,更安全,后连接或直接连接到数据库?

时间:2013-03-11 12:32:16

标签: android ios http-post memory-efficient mysqlconnection

我想将许多数据插入到mysql数据库中,当然只有文本。

我目前正在通过帖子进行操作,例如insertUser.php?user=asd&pass=asdas&email=asdasd,如果可以,它会给我一个回复,但现在我正在尝试upload大量数据insertData.php?xml=string&userid=2而且响应也很大,有时会花费很长时间,因为手机应用大多使用 3g(android& iOS),因此效率更高,仍然在做post connectionsdirect mysql connection

感谢。

1 个答案:

答案 0 :(得分:1)

检查下面的答案

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];