views:

28

answers:

2

Hello stackoverflow,

So I am trying to create a request that will automatically follow the redirects in its process. For some reason this is not working, this is what my delegate method looks like. Do I need to do anything else for this to function properly? Thanks!

-(NSURLRequest *)connection:(NSURLConnection *)connection
        willSendRequest:(NSURLRequest *)request
       redirectResponse:(NSURLResponse*)redirectResponse {
NSLog(@"RedirectResponse:%@", [redirectResponse URL]);
NSLog(@"send request:%@", [request URL]);

NSHTTPCookieStorage *cookieDict = [NSHTTPCookieStorage sharedHTTPCookieStorage];
NSLog(@"CURRENT COOKIES: %@", [cookieDict cookies]);

/*NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse*)redirectResponse;
if ([redirectResponse respondsToSelector:@selector(allHeaderFields)]) {
    NSDictionary *dictionary = [httpResponse allHeaderFields];
    NSLog([dictionary description]);
}*/

NSURLRequest *newRequest=request; 
return newRequest;

}

A: 

The documentation says:

The delegate may return request unmodified to allow the redirect

So a simple return request; should be enough.

Are you sure it is not working? What do you see?

St3fan
It's working, but not following the redirects properly. I feel like it must be a server side error. Or perhaps I need to backtrack in the process. I need to trace through a login procedure and collect the cookies along the way. This should function for that purpose correct?
gabaum10
A: 

Figured it out, had the wrong post data/target. Thanks for helping me understand how that worked! I am going to accept your answer. :)

gabaum10