Xcode/Cocoa newbie problem capturing URL of a 307 redirect

Discussion in 'Mac Programming' started by steveclv, Jul 16, 2009.

  1. macrumors newbie

    Joined:
    Mar 31, 2008
    #1
    I'm a complete newbie at Cocoa but having a go anyway :)

    I have an Xcode/Cocoa app that is reading a web URL and extracting the data which it then parses, however the info that is needed is now contained within the URL of a redirection page - not in the content of the new page itself.

    So for example I originally read http://www.mydomain.com and in the content of that page is a parameter called Fred=66 that was parsed out.

    Now, http://www.mydomain.com redirects to http://www.mydomain.com/?fred=66 using a 307 redirect.

    The code is currently

    NSString* reply = [[NSString alloc] initWithData: data encoding: NSASCIIStringEncoding];
    NSArray* parts = [reply componentsSeparatedByString:mad:": "];
    NSEnumerator* e = [parts objectEnumerator];
    NSString* s;

    Followed by the parsing code.

    But how can I change this to read the URL of the new redirected page and not it's contents?

    Any hints or advice appreciated!
     
  2. Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #2
    Use NSURLConnection and the connection:willSendRequest:redirectResponse: delegate method to get the redirect URL.
     
  3. thread starter macrumors newbie

    Joined:
    Mar 31, 2008
    #3
    Thanks!

    The code I am using is

    - (void) parseGwIdData:(NSURLRequest *)connection:(NSURLConnection *)connection
    willSendRequest:(NSURLRequest *)request
    redirectResponse:(NSURLResponse *)redirectResponse
    {
    NSURLRequest *newRequest=request;
    if (redirectResponse) {
    newRequest=nil;
    }
    return newRequest;
    }

    and I am calling parseGwIdData as follows

    [self getGwIdFrom:mad:"http://mydomain.com"];

    However when building I am getting a fatal error saying "error: conflicting type for connection"

    In the call to getGwIdFrom do I need to do something to the URL and if so what?

    Thanks for your help on this - it's a steep learning curve !
     

Share This Page