NSURLDownload Error

  • I'm attempting to send a POST request from my Cocoa app, and then
    handle the subsequent download.  I've gone through a bit of
    information via a blog regarding how to actually send a post request,
    and have attempted to implement it, however I seem to be having an
    issue.  My code follows:

    @implementation LoginHandler
    - (void)beginLogin:user_id withKey:api_key andSpinner:statusSpinner
    {
    NSString *post = [NSString stringWithFormat:@"userID=%@&apiKey=%@",
    user_id, api_key];
    NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding
    allowLossyConversion:YES];

    NSString *postLength = [NSString stringWithFormat:@"%d", [postData
    length]];

    NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init]
    autorelease];
      [request setURL:[NSURL URLWithString:@"http://api.eve-online.com/account/Characters.xml.aspx
    "]];
      [request setHTTPMethod:@"POST"];
      [request setValue:postLength forHTTPHeaderField:@"Content-Length"];
      [request setValue:@"application/x-www-form-urlencoded"
    forHTTPHeaderField:@"Content-Type"];
      [request setHTTPBody:postData];

    NSURLDownload *loginRequest = [[NSURLDownload alloc]
    initWithRequest:request delegate:self];

    [statusSpinner startAnimation:self];

    if (loginRequest)
    {
      NSLog(@"Download Started");
      //[loginRequest setDestination:@"/Users/eric/" allowOverwrite:YES];
    }
    else
    {
      NSLog(@"Error");
    }
    [statusSpinner stopAnimation:self];
    }

    - (void)download:(NSURLDownload *)download didReceiveResponse:
    (NSURLResponse *)response
    {
    NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)response;
    NSDictionary *httpResponseHeaderFields = [httpResponse
    allHeaderFields];
    NSLog(@"Response Received: \n\n%@", httpResponseHeaderFields);
    }

    - (void)downloadDidFinish:(NSURLDownload *)download
    {
    [download release];
    NSLog(@"%@", @"downloadDidFinish");
    }

    - (void)download:(NSURLDownload *)download didFailWithError:(NSError
    *)error
    {
    [download release];
    NSLog(@"Download failed! Error - %@ %@", [error
    localizedDescription], [[error userInfo]
    objectForKey:NSErrorFailingURLStringKey]);
    }

    @end

    The resulting output is as such:

    2007-11-11 02:55:31.556 Eve Online Monitor[10353:10b] Download Started
    2007-11-11 02:55:31.868 Eve Online Monitor[10353:10b] Response Received:

    {
        "Cache-Control" = private;
        "Content-Type" = "application/xml; charset=utf-8";
        Date = "Sun, 11 Nov 2007 07:55:31 GMT";
        Server = "Microsoft-IIS/6.0";
        "Transfer-Encoding" = Identity;
        "X-Aspnet-Version" = "2.0.50727";
        "X-Powered-By" = "ASP.NET";
    }
    2007-11-11 02:55:31.872 Eve Online Monitor[10353:10b] Download failed!
    Error - Cannot open file http://api.eve-online.com/account/Characters.xml.aspx

    No manner of modifying the code has resulting in any variation, which
    is quite odd cause simply going to the URL itself provides a result.
    However, doing a curl on the fully formed url returns fine.  Any
    assistance would be greatly appreciated.
previous month november 2007 next month
MTWTFSS
      1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30    
Go to today