Can someone please write the simplest working code that the last redirected url (nth) can get when I get the url for GET?
I know that I need to use asynchronous requests, but I cannot develop a complete working code that solves the problem.
I am using ios5, so I can use the latest added asynchronous built-in functions in ios5.
I have tried many things, but I have not yet succeeded. Using the code below, I am trying to send a receive request with parameters, but somehow these parameters are lost due to redirecting the site: (!
NSURLRequest *request = [NSURLRequest requestWithURL:urlOriginal];
[NSURLConnection
sendAsynchronousRequest:request
queue:[NSOperationQueue mainQueue]
completionHandler:^(NSURLResponse *response, NSData *data, NSError *error)
{
NSLog("the returned data should be the final data of the redirected url with parameters but it is not");
}];
}
EDIT
So here is what I did now:
NSURLRequest *requestOriginal = [NSURLRequest requestWithURL:urlOriginal];
NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:requestOriginal delegate:self];
[connection start];
and delegate:
-(NSURLRequest *)connection:(NSURLConnection *)connection
willSendRequest:(NSURLRequest *)request
redirectResponse:(NSURLResponse *)redirectResponse
{
if (redirectResponse) {
NSMutableURLRequest *r = [request mutableCopy];
[r setURL: [request URL]];
return r;
} else {
NSLog(@"redirecting to : %@", [request URL]);
return request;
}
}
URL- , get.
, ? Handler?
edit2:
, :
(void) connection: (NSURLConnection *) connection didReceiveResponse: (NSURLResponse *) response
(void) : (NSURLConnection *) didReceiveData: (NSData *)
(void) connection: (NSURLConnection *) connection didFailWithError: (NSError *) error
(void) connectionDidFinishLoading: (NSURLConnection *)