PDA

View Full Version : NSURLConnection Delegate RedirectResponse is always nil




roeik
Dec 29, 2009, 12:06 PM
Hi all,

I have this problem that is driving me insane. I am using the WillSendRequest RedirectResponse delegate method of NSURLConnection to find out if I am being redirected. The problem is that it doesn't work properly. RedirectResponse for some reason is always nil, and "request" seems to be the original request instead of the request with the redirect url.

Any idea why it is doing this?

Please help.

Here is the code:


-(NSURLRequest *)connection:(NSURLConnection *)connection willSendRequest:(NSURLRequest *)request redirectResponse:(NSURLResponse *)redirectResponse
{
NSURLRequest *newRequest=request;

NSLog(@"Request: %@",[[request URL] absoluteURL]);
NSLog(@"The Request: %@",[[theRequest URL] absoluteURL]);

if (redirectResponse) {
NSLog(@"redirect requested!");
[connection cancel];
[connection release];
[receivedData release];
[updateController cancelDownloaders];
[updateController alertSimpleAction: @"Could not download file. \n Please check your username and password"];
newRequest=nil;
}

return newRequest;
}



roeik
Dec 30, 2009, 02:37 AM
I am surprised nobody had this problem before.

I would take any advice about hot to top a connection when the request is being redirected to another page.

robbieduncan
Dec 30, 2009, 07:12 AM
1) Don't bump your posts. It's amazingly rude and arrogant as well as being against the forum rules. So much so that I almost did not post point 2

2) As per the documentation redirectResponse "May be nil in cases where this method is not being sent as a result of involving the delegate in redirect processing."

roeik
Dec 30, 2009, 08:27 AM
Hi,

Regarding point 1, Sorry. I am not sure what you mean by bump up, but I apologize if I caused you any damage of any sort. The last thing i meant was to be arrogant or rude, and again, I am deeply sorry if I broke the forum rules. Thank you for letting me know.

Regarding point 2, I read the documentation as well and saw this point, but I guess it was and still is vague to me. And it doesn't solve me the problem. My URLResponse is being redirected to another page, yet the redirect delegate method is being called and the redirect is nil. Why would this method get called if there is no redirect call? I don't understand.

robbieduncan
Dec 30, 2009, 08:36 AM
I think you are misunderstanding what the redirectResponse should/will contain. In the case where you receive a redirect and the delegate has not yet been involved the redirectResponse will be nil (this is my understanding of what the documentation is saying). The request variable is what will be sent (i.e. where you have been redirected to). If you want to alter than you should copy and change it before returning.