2011-12-15 36 views
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工作?

委託的實現是非常基本的,它只是處理的方式響應,並將其保存到數據庫中。

回答

0

如果我理解你的權利,你想爲每個testVariable的請求,你應該把NSMutableURLRequest定義到for循環。

0

瘋狂的猜測:在請求之間放置一個10秒的時間間隔,以查看他的行爲是否有任何改變。