NSURL *url = [NSURL URLWithString:@"http://test.com"];
NSMutableURLRequest *post = [NSMutableURLRequest requestWithURL:url
cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0];
for (TestVariable *testVariable in variables)
{
NSData *testVariable=[self getJSONTestVariable:testVariable];
NSString *data=[[NSString alloc]initWithData:maintenanceData encoding:NSUTF8StringEncoding];
[post setHTTPMethod:@"POST"];
[post setValue:@"application/json" forHTTPHeaderField:@"Accept"];
[post addValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
[post addValue:[NSString stringWithFormat:@"%d", [data length]] forHTTPHeaderField:@"Content-Length"];
[post setHTTPBody: [data dataUsingEncoding:NSUTF8StringEncoding ]]; TestVariableDelegate *sjd= [TestVariableDelegate alloc];
NSURLConnection *connection = [[NSURLConnection alloc]initWithRequest:post delegate:sjd];
[connection start];
}
这段代码的问题是,我尝试发送的 2-3-100 元素中只有一个被发送,我不知道如何解决这个问题。
委托的实现非常基本,它只是以某种方式处理响应并将其保存到数据库中。