NSURLConnection Delegate RedirectResponse is always nil

Discussion in 'iPhone/iPad Programming' started by roeik, Dec 29, 2009.

  1. macrumors member

    Joined:
    Dec 25, 2008
    #1
    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:


    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;
    }
     
  2. thread starter macrumors member

    Joined:
    Dec 25, 2008
    #2
    Anyone??

    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.
     
  3. Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #3
    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."
     
  4. thread starter macrumors member

    Joined:
    Dec 25, 2008
    #4
    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.
     
  5. Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #5
    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.
     

Share This Page