2

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

例如,我目前正在通过帖子进行insertUser.php?user=asd&pass=asdas&email=asdasd操作,无论是否正常,它都会给我回复,但现在我正在尝试处理upload大量数据insertData.php?xml=string&userid=2,例如回复也很大,有时需要很长时间因为是针对手机应用多使用3g(android & iOS),所以哪个效率更高,还在做post connections还是一个direct mysql connection

谢谢。

4

1 回答 1

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];
于 2013-03-11T13:02:15.897 回答