NSMutableURLRequest和重定向 [英] NSMutableURLRequest and redirection

查看:142
本文介绍了NSMutableURLRequest和重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我正在尝试创建一个请求,该请求将自动跟踪其进程中的重定向。由于某种原因,这不起作用,这是我的委托方法的样子。我还需要做其他事情才能正常运作吗?谢谢!

   - (NSURLRequest *)连接:(NSURLConnection *)连接
willSendRequest:(NSURLRequest *)request
redirectResponse:(NSURLResponse *)redirectResponse {
NSLog(@RedirectResponse:%@,[redirectResponse URL]);
NSLog(@发送请求:%@,[请求URL]);

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

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

NSURLRequest * newRequest = request;
返回newRequest;

}

解决方案

文档说:


委托可以返回未修改的请求以允许重定向


所以一个简单的返回请求; 就足够了。



<你确定它不起作用吗?你看到了什么?


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;

}

解决方案

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?

这篇关于NSMutableURLRequest和重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆