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 要素の 1 つだけが送信され、問題の解決方法がわからないことです。

デリゲートの実装は非常に基本的なもので、応答を処理してデータベースに保存するだけです。

4

2 に答える 2

0

私が正しく理解し、各 testVariable に対して要求を行いたい場合は、NSMutableURLRequest定義を for ループに入れる必要があります。

于 2011-12-15T07:58:55.220 に答える
0

大げさな推測: 要求の間に 10 秒の間隔を置いて、彼の行動に変化があるかどうかを確認します。

于 2011-12-15T07:58:57.157 に答える