Resolved AFNEtworking 2.0 POST works but says fail ??

Discussion in 'iOS Programming' started by IDMah, Mar 31, 2014.

  1. IDMah, Mar 31, 2014
    Last edited: Apr 4, 2014

    IDMah macrumors 6502

    IDMah

    Joined:
    May 13, 2011
    #1
    Hi all.

    I'm moving my app from earlier version of AFNetworking to 2.0.

    The POST seem to work (see it added to mysql) but it's returning an error.
    very confusing.

    Code:
            NSURL *url = [NSURL URLWithString:PUTURL]; // PUTURL set to http://localion_of_PHP/
                    AFHTTPRequestOperationManager *httpClient = [[AFHTTPRequestOperationManager manager] initWithBaseURL:url]; 
                     
                    // PUTPHP = PHPcode.php //             
          // httpClient.requestSerializer = [AFJSONRequestSerializer serializer];                 
           [httpClient POST:PUTPHP parameters:paramass success:^(AFHTTPRequestOperation *operation, id responseObject) {
                        NSString *responseStr = [[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding];
                        NSLog(@"Request Successful, response '%@'", responseStr);
                        sharedHSData.queuedItems=NO;
                        
                        uploadError = NO;
                        [[NSNotificationCenter defaultCenter] postNotificationName:@"JSONCOMPLETED"
                                                                            object:nil];
                        
                    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
                        // if we fail add the score to a send Que and load the old // 
                        NSLog(@"ID= %i [Alert Send HTTPClient Error]: %@",highScoreIdent, error.localizedDescription);
     
                        [self enableOKButton];
                        
                    }]
    
    
    Here is the Error:
    Code:
     ID= 0 [Alert Send HTTPClient Error]: The operation couldn’t be completed. (Cocoa error 3840.)
    
    ideas??
    thanks
    Ian
     
  2. IDMah thread starter macrumors 6502

    IDMah

    Joined:
    May 13, 2011
    #2
    Sussed!

    I needed to format the response.. (serialize)

    added.
    Code:
    httpClient.responseSerializer = [AFHTTPResponseSerializer serializer];
    
     
  3. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #3
    Please make this thread as Resolved then. Thank you.
     

Share This Page