-1

我一直在为我的所有 Http Request 使用 AFNetworking 库,我的示例请求如下所示

AFJSONRequestOperation *operation = [[AFJSONRequestOperation alloc] initWithRequest:requestObj];
    [operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id   responseObject) {

        [dic setValue:operation forKey:@"operationObj"];
        [dic setValue:responseObject forKey:@"jsonData"];

        [requestedView performSelector:callBackFunction withObject:[NSNumber numberWithBool:YES] withObject:dic];

    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {

        NSLog(@"Error resopnse => %@",error);

        [dic setValue:operation forKey:@"operationObj"];
        [dic setValue:error forKey:@"error"];

        [requestedView performSelector:callBackFunction withObject:[NSNumber   numberWithBool:YES] withObject:dic];
    }];

当我第一次发出 Http 请求时,操作队列需要很长时间才能启动,有时我会导致 0 作为响应状态代码

但是一旦我尝试再次触发相同的请求,我就没有遇到任何问题。

我错过了什么吗?

提前致谢

4

1 回答 1

0

我不确定您的请求是什么,但完成和成功块应该会影响请求的开始时间。我通常AFJSONRequestOperation像这样使用 s:

AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {
    // Success
} failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id JSON) {
    // Failure
}];

[operation start];

有没有[operation start]我们看不到的电话?

于 2013-01-04T16:00:38.153 回答