开发者

NSMutableURLRequest and redirection

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 COO开发者_Python百科KIES: %@", [cookieDict cookies]);

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

NSURLRequest *newRequest=request; 
return newRequest;

}


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?


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜