AFNetworking Erwartet status code in (200-299), got 403

Versuchen zu migrieren meinen code aus ASIHttpRequest zu AFNetworking. Es scheint, ähnliche Fragen gestellt wurden aber couldnt finden die Lösung für mein problem.

Mein code war in Ordnung arbeiten mit ASIHttpRquest.

Schicke ich einen einfachen post-request an meinen server und hören http-Antworten. Wenn http response 200 funktioniert alles wunderbar, aber wenn ich senden Sie ein anderer status-code - >400 AFNetworking block schlägt fehl.

Server-Seite die Antwort:

$rc = $stmt->fetch();
    if ( !$rc ) {
    // echo "no such record\n";
      $isrecordExist=0; //false does not exists
      sendResponse(403, 'Login Failed');
      return false;
    }
    else {
     //echo 'result: ', $result, "\n";
       $sendarray = array(
            "user_id" => $result,
        );
        sendResponse(200, json_encode($sendarray));
    }

IOS Teil:

AFHTTPClient *client = [[AFHTTPClient alloc] initWithBaseURL:
                            [NSURL URLWithString:server]];
    client.allowsInvalidSSLCertificate=YES;

    [client postPath:loginForSavingCredientials parameters:params success:^(AFHTTPRequestOperation *operation, id response) {
    if (operation.response.statusCode == 500) {}
     else if (operation.response.statusCode == 403) {}
     else if (operation.response.statusCode == 200) {//able to get results here            NSError* error;
        NSString *responseString = [[NSString alloc] initWithData:response encoding:NSUTF8StringEncoding];
        NSDictionary* json =     [NSJSONSerialization JSONObjectWithData: [responseString dataUsingEncoding:NSUTF8StringEncoding]
                                                                 options: NSJSONReadingMutableContainers
                                                                   error: &error];}
 } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        NSLog(@"failure %@", [error localizedDescription]);
    }];

NSLOG:

 failure Expected status code in (200-299), got 403

Wie kann ich dieses Problem beheben?

InformationsquelleAutor u.gen | 2013-05-30

Schreibe einen Kommentar