Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7948017
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T01:36:00+00:00 2026-06-04T01:36:00+00:00

Can someone please post the simplest of working code that can get the last

  • 0

Can someone please post the simplest of working code that can get the last redirected url(nth) when I GET request a url?

I know I need to use asynchronous requests but I am not able to work out a complete working code that solves the problem.

I am using ios5 so I can use the latest added asynchronous inbuilt functionalities in ios5.

I have tried a lot of things but I am not successful still. Using the below code I am trying to send a get request with parameters but somehow those parameters are getting lost due to site’s redirection :(!

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 this is what I have done 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]; // original request
    [r setURL: [request URL]];
    return r;
} else {
     NSLog(@"redirecting to : %@", [request URL]);
    return request;
}
}

and the log gives me the correct request url that i need along with the originally passed get parameters.

Now how to I get the data from this request? Another completionHandler delegate method?

edit2 :

Ok so I implemented the other delgates as well :

  • (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response

  • (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data

  • (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error

  • (void)connectionDidFinishLoading:(NSURLConnection *)connection

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T01:36:02+00:00Added an answer on June 4, 2026 at 1:36 am

    Please read Handling Redirects and Other Request Changes in the documentation. Briefly, you’ll want to a) provide a delegate for your connection, and b) implement the method connection:willSendRequest:redirectResponse: in said delegate. I don’t understand exactly what you’re trying to do in your question — do you just want the data from URL to which your connection is redirected, or do you want to see the redirected request? Either way, implementing the method above should help. Your delegate will be able to see the redirected request, and returning it unchanged should cause the connection to load the new URL.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can someone please post a simple code that would convert, System::String^ To, C++ std::string
Can someone please explain how you can write a url pattern and view that
i know this sounds silly, but can someone please post the arrays described by
I am a complete beginner here. Can someone please post some Delphi code to
Can someone please explain the major differences between Scala, Groovy and Clojure. I know
Can someone please check out this code, i really dont understand why i got
Can someone please provide a multipart/form-data POST example based on: How can I unit
Can someone please explain this to me? I have the following code: <form action=<?php
Can someone please post an example on how to create a many to many
Can someone please tell me what I'm doing wrong here. I've done a post

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.