Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/wcf/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios AFNetworking:setRedirectResponseBlock在我的类NSURLResponse中始终返回空值_Ios_Objective C_Ios6_Afnetworking - Fatal编程技术网

Ios AFNetworking:setRedirectResponseBlock在我的类NSURLResponse中始终返回空值

Ios AFNetworking:setRedirectResponseBlock在我的类NSURLResponse中始终返回空值,ios,objective-c,ios6,afnetworking,Ios,Objective C,Ios6,Afnetworking,我正在使用AFNetworking类与web服务交互。我在这方面遇到了一些问题 AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc]initWithRequest:theRequest];// using AFHTTPRequestOperation to request Data [operation setRedirectResponseBlock:^NSURLRequest *(NSURLConnection

我正在使用AFNetworking类与web服务交互。我在这方面遇到了一些问题

AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc]initWithRequest:theRequest];// using AFHTTPRequestOperation to request Data
[operation setRedirectResponseBlock:^NSURLRequest *(NSURLConnection *connection, NSURLRequest *request, NSURLResponse *redirectResponse) {
        NSLog(@"connection :%@",connection);

        NSLog(@"request :%@",request);

        NSLog(@"response :%@",redirectResponse); question 1:? i get NSURLResponse value is null. output:response :(null)

        return request;

    }];
在断点的帮助下,我检查AFURLConnectionOperation类(类名:AFURLConnectionOperation.m)中是否有来自服务器的响应?是的,它得到了回应

- (void)setRedirectResponseBlock:(NSURLRequest * (^)(NSURLConnection *connection, NSURLRequest *request, NSURLResponse *redirectResponse))block {

    self.redirectResponse = block;

    NSLog(@"connection :%@",_connection);

    NSLog(@"request :%@",_request);

    NSLog(@"response :%@",_redirectResponse);//getting NSURLResponse from server.(its showing response)  output: response :<__NSGlobalBlock__: 0x46238>

    NSLog(@"block :%@",block);

}

请帮助我解决这个问题,非常感谢您的示例。

根据相应委托方法的文档,
连接:willSendRequest:redirectResponse:

在发送请求之前,代理可以通过修改请求来接收此消息,例如,将请求的URL转换为其规范形式。要检测这种情况,请检查重定向响应;如果为nil,则由于重定向而未发送消息


是的,我理解。我正在使用AFHTTPRequestOperation在我的nsoperation类中启动操作,所以我的问题是有没有办法调用所有委托方法(DidReceiveRespose、didfinishloading、didfailwitherror、didReceiveData)进入我的nsoperation类,而不是使用块。我只想在我的nsoperation类中调用这些委托方法。你能帮我一下吗?这些块有效地替换了你本来要实现的所有委托方法。如果您真的愿意,可以在子类中重新实现它们,但我不推荐这样做。连接:willSendRequest:redirectResponse:{If(self.redirectResponse){NSLog(@“connection:%@”,connection);NSLog(@“request:%@”,request);NSLog(@“response:%@”,redirectResponse);//is.return self.redirectResponse(连接、请求、redirectResponse);我检查此redirectResponse是否为null,但仍然找不到错误所在。
if ([response isKindOfClass:[NSHTTPURLResponse self]]) {

NSDictionary *headers = [(NSHTTPURLResponse *)response allHeaderFields];

NSString *modified = [headers objectForKey:@"Last-Modified"];


if (modified) { .......