1

I send request, but don't call method connectionDidFinishLoading, why?

- (void)startHttpRequestWithCookie:(NSArray *)authCookies
{
    NSURL *url = [NSURL URLWithString:@"http://test.test/mbox.php"];
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0];

    NSDictionary* headers = [NSHTTPCookie requestHeaderFieldsWithCookies:authCookies];
    [request setHTTPShouldHandleCookies:NO];
    [request setHTTPMethod:@"POST"];
    [request setValue:@"text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8" forHTTPHeaderField:@"Accept"];
    [request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
    [request setAllHTTPHeaderFields:headers];
   NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];

    if (connection) {
        // Create the NSMutableData to hold the received data.
             responseData = [NSMutableData new];
    } else {
        // Inform the user that the connection failed.
    }
}

  - (void) connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
        [responseData setLength:0];
    }

- (void) connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
        [responseData appendData:data];
    }

- (void) connectionDidFinishLoading:(NSURLConnection *)connection {
        NSString* responseString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
        NSLog(@"%@", responseString);
        NSError *error = nil;
        NSData* data = [responseString dataUsingEncoding:NSUTF8StringEncoding];

etc..
    }

This is my code, I can not understand why is not called connectionDidFinishLoading

thank you very much for your time

Alexander
  • 627
  • 2
  • 11
  • 23
  • 2
    check to see if the other delegate methods are called; could the connection be failing? Did you implement didFailWithError? – Rick Trapp Apr 17 '13 at 18:02
  • Thanks. Error "Connection failed! Error - too many HTTP redirects Error Domain=NSURLErrorDomain Code=-1007 "too many HTTP redirects" UserInfo=0x7592ad0 " – Alexander Apr 17 '13 at 18:09

1 Answers1

2

Try implementing - (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response and checking the values returned in the response object.

Brent Westmoreland
  • 463
  • 1
  • 4
  • 6