0
我想批量发送到服务器上的数据。 我必须一次发送25个字符串的nsmutablestring数据,然后得到响应,如果响应成功,然后再次发送下一批。 我使用,我使用的HttpConnection class.The代码如下:发送数据到服务器使用for循环的HTTP POST在iPhone
HttpConnectionClass * ht= [[HttpConnectionClass alloc] init];
ht.delegate=self;
ht.isNetworkIndicator = YES;
NSString *data = @"" ;
int i = 0;
self.dataforserver = [[NSMutableString alloc]init] ;
[self.dataforserver setString:@""];
for (i=0;i<= self.dataArray.count-1; i++) {
data =[NSString stringWithFormat:@"A%d%@",[[self.recordIDArray objectAtIndex:i]intValue], [self.dataArray objectAtIndex:i]];
[self.dataforserver appendString:data];
if ((i+1)%25 == 0 && i!=0) {
[ht makeHttpConnection:[NSString stringWithFormat:@"http://www.url.com?action=%d&subscriberid=%d&type=%@",2,56904,@"full"] withData:self.dataforserver];
NSLog(@"in for loop dataforserver is %@",dataforserver);
[dataforserver setString:@""];
}
}
if (dataforserver != @"") {
NSLog(@"not in for loop dataforserver is %@",dataforserver);
[ht makeHttpConnection:[NSString stringWithFormat:@"http://www.url.com?action=%d&subscriberid=%d&type=%@",2,56904,@"full"] withData:self.dataforserver];
}
我得到下面的方法回应
-(void)getHttpData:(NSObject*)data isError:(BOOL)isErr errorMsg:(NSString*)err{
NSString *response=(NSString*)data;
NSLog(@"response is %@",response);
}
我想继续循环只有当我得到的回应“成功”。 任何人都可以建议如何实现它。 我很新iOS编程。请帮助