0
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元素我想送一個被髮送,我不知道如何解決這個問題。如何使此NSURLConnection工作?
委託的實現是非常基本的,它只是處理的方式響應,並將其保存到數據庫中。