如何在AFNETWORKING中为参数设置多个值

时间:2013-07-09 06:43:13

标签: ios objective-c parameters afnetworking

我想在服务器上删除多个文件,我需要为服务器发送多个参数值。例如:upload_id =“11,12,13”,每个值都是以逗号分隔的字符串。我使用过NSArray,但它不起作用。服务器响应不成功。这是我的代码:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if([_tableView cellForRowAtIndexPath:indexPath].accessoryType == UITableViewCellAccessoryCheckmark){
        [_tableView cellForRowAtIndexPath:indexPath].accessoryType = UITableViewCellAccessoryNone;
    }else{
        [_tableView cellForRowAtIndexPath:indexPath].accessoryType = UITableViewCellAccessoryCheckmark;
    }
    NSArray *selectedRows = [_tableView indexPathsForSelectedRows];

    for (NSIndexPath *indexPath in selectedRows) {
        uploadidString =[uploadidArray objectAtIndex:indexPath.row];
    }
    [iduploadArray insertObject:uploadidString atIndex:0];
    NSLog(@"ID UPLOAD Array %@",iduploadArray);
}

-(void) deleteItems 
{
    NSURL *url1 = [NSURL URLWithString:@"http://myserver"];
    AFHTTPClient *httpClient = [[AFHTTPClient alloc] initWithBaseURL: url1] ;

    NSDictionary *params1 = @{
                              @"upload_id" :  [NSArray arrayWithObjects:iduploadArray,nil],

                              };

    NSMutableURLRequest *afRequest = [httpClient requestWithMethod:@"POST" path:nil parameters:params1] ;
    AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:afRequest];

    [operation  setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
        NSLog(@"Success");
        NSString * parsexmlinput = [[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding];
        NSLog(@"Response in Delete items: %@", parsexmlinput); 
        [self parseXMLFile:parsexmlinput];


    }
                                      failure:^(AFHTTPRequestOperation *operation, NSError *error) {
                                          NSLog(@"error: %@", error);

                                      }
     ];
    [httpClient enqueueHTTPRequestOperation:operation];


}

你有什么建议吗?

1 个答案:

答案 0 :(得分:4)

创建参数时,使用数组上的componentsJoinedByString:@","将其转换为所需格式的字符串:

@"upload_id" : [iduploadArray componentsJoinedByString:@","],