[英]Which is more efficient and secured way, post connection or direct connection to a database?
I want to insert many data to a mysql database, only text of course. 我想将许多数据插入到mysql数据库中,当然只有文本。
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
? 我目前正在通过帖子进行操作,例如
insertUser.php?user=asd&pass=asdas&email=asdasd
,如果一切正常,它会给我一个响应,但是现在我正在尝试upload
大量数据,例如insertData.php?xml=string&userid=2
并且响应也很大,有时会花费很长时间,因为它主要用于使用3g(Android和iOS)的手机应用程序,因此效率更高,仍然可以进行post connections
或direct mysql connection
?
Thanks. 谢谢。
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];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.