How do I get the redirected url using AFNetworking?

I am using AFNetworking get method, the url looks something like this:

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

Using chrome, I can see that the true url is: enter image description here

He is in this place.

How can I get the url when using AFNetworking, I tried the following method, it doesn't work

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

    }
];

      

Answer

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";
}

      

no location field, how can i get this? thank.

+3


source to share


1 answer


I figured the answer was using the following method:



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];

      

+4


source