【问题标题】:How to get the redirected URL using AFNetworking?如何使用 AFNetworking 获取重定向的 URL?
【发布时间】:2015-05-30 16:20:16
【问题描述】:

我使用 AFNetworking get 方法,url 类似于:

http://www.hi-pda.com/forum/redirect.php?from=notice&goto=findpost&pid=31089630&ptid=1631932

使用 chrome 我可以看到真正的 URL 是:

它在那个位置。

使用AFNetworking时如何获取url,我试过下面的方法,还是不行

[
    manager GET:threadNotice.URLString
    parameters:nil
    success:^(AFHTTPRequestOperation *operation, id responseObject) {
        NSLog(@"%@",[operation.response allHeaderFields]);
    }
    failure:^(AFHTTPRequestOperation *operation, NSError *error) {

    }
];

回复是

2015-05-31 00:11:03.349 HiPDA V2[20006:751020] {
    Connection = "keep-alive";
    "Content-Encoding" = gzip;
    "Content-Type" = "text/html";
    Date = "Sat, 30 May 2015 16:10:59 GMT";
    Server = "nginx/1.6.2";
    "Transfer-Encoding" = Identity;
    "X-Powered-By" = "PHP/5.3.10";
}

没有位置字段,我怎样才能得到它?谢谢。

【问题讨论】:

    标签: html ios afnetworking afnetworking-2


    【解决方案1】:

    我使用以下方法解决了答案:

    AFHTTPRequestOperation *requestOperation=[[AFHTTPRequestOperation alloc] initWithRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:_URLString]]];
        [requestOperation setRedirectResponseBlock:^NSURLRequest *(NSURLConnection *connection, NSURLRequest *request, NSURLResponse *redirectResponse) {
            if (redirectResponse) {
                //this is the redirected url
                NSLog(@"%@",request.URL);
            }
            return request;
        }];
        [requestOperation start];
    

    【讨论】:

    • 我在这里找到的最简单的答案!
    猜你喜欢
    • 2012-07-26
    • 2011-06-21
    • 1970-01-01
    • 1970-01-01
    • 2011-03-22
    • 2018-05-02
    • 1970-01-01
    相关资源
    最近更新 更多