title: restkit ios: authentication start failing, if user provide wrong credential in first attempt and correct credential in subsquent attempts
body: <p>When application is failed to login/authenticate successfully with restkit in first attempts due to wrong username or password, application never get success even with correct username and password, any help would be appreciated in this.
  On login button i create the restkit instance and pass the information here is the code</p>
  
  <pre><code>func sendLoginRequest(userName:String,password:String){
  
          let authenticate:String = String(format: "%@:%@",  userName, password)
          let plainData = (authenticate as NSString).dataUsingEncoding(NSUTF8StringEncoding)
          let base64String = plainData!.base64EncodedStringWithOptions(NSDataBase64EncodingOptions(rawValue: 0))
          print(base64String)
          headers  = ["Authorization" : String(format: "Basic %@",  base64String)]
          self.webInterface = DFWebInterface.shareWebInterface(DFModel.sharedInstance.bMockServer)
  
          self.webInterface?.sendRequest(nil,request: LOGIN.rawValue, nil,headers: headers as! [NSObject : AnyObject])
      }
  </code></pre>
  
  <p>then initialize my web interface class</p>
  
  <pre><code>-(id)init:(NSString*)strURL :(BOOL)mockServer{    
      if(nil!=(sDFWebInterface=[super init])){
          NSURL *baseURL = [NSURL URLWithString:strURL];
          DFAFHTTPClient* client=[[DFAFHTTPClient alloc] initWithBaseURL:baseURL];
          sDFWebInterface-&gt;rkobjmanagerDF = [[RKObjectManager alloc] initWithHTTPClient:client];
              [RKMIMETypeSerialization registerClass:[RKNSJSONSerialization class] forMIMEType:@"text/plain"];
  
          [AFNetworkActivityIndicatorManager sharedManager].enabled = YES;
      }
  
      return sDFWebInterface;
  }
  </code></pre>
  
  <p>After initializing i create mapping and send post request
  Everything works fine if application send correct credential very first time</p>
  
  <p>Here is the log for second time fail even application passing correct credential</p>
  
  <p>2016-02-11 12:07:44.242 MyProject[7033:94063] I restkit.network:RKObjectRequestOperation.m:150 POST '<a href="https://myproject-dev.apps.mycompany-iot-cloud.com/api/v1/authenticate" rel="nofollow">https://myproject-dev.apps.mycompany-iot-cloud.com/api/v1/authenticate</a>'
  2016-02-11 12:07:45.215 MyProject[7033:95645] E restkit.network:RKObjectRequestOperation.m:551 Object request failed: Underlying HTTP request operation failed with error: Error Domain=org.restkit.RestKit.ErrorDomain Code=-1011 "Expected status code in (200), got 401" UserInfo={NSLocalizedRecoverySuggestion={"timestamp":"2016-02-11T06:37:45.103+0000","status":401,"error":"Unauthorized","message":"Failed authenticating with username and password","path":"/api/v1/authenticate"}, NSErrorFailingURLKey=<a href="https://myproject-dev.apps.mycompany-iot-cloud.com/api/v1/authenticate" rel="nofollow">https://myproject-dev.apps.mycompany-iot-cloud.com/api/v1/authenticate</a>, AFNetworkingOperationFailingURLRequestErrorKey= { URL: <a href="https://myproject-dev.apps.mycompany-iot-cloud.com/api/v1/authenticate" rel="nofollow">https://myproject-dev.apps.mycompany-iot-cloud.com/api/v1/authenticate</a> }, AFNetworkingOperationFailingURLResponseErrorKey= { URL: <a href="https://myproject-dev.apps.mycompany-iot-cloud.com/api/v1/authenticate" rel="nofollow">https://myproject-dev.apps.mycompany-iot-cloud.com/api/v1/authenticate</a> } { status code: 401, headers {
      "Cache-Control" = "no-cache, no-store, max-age=0, must-revalidate";
      "Content-Length" = 171;
      "Content-Type" = "application/json;charset=UTF-8";
      Date = "Thu, 11 Feb 2016 06:37:44 GMT";
      Expires = 0;
      Pragma = "no-cache";
      Server = "";
      "Set-Cookie" = "<strong>VCAP_ID</strong>=7487ff5a5d1940b895d0459b91eaec009a55f1ebd2774084b28fc6d24cab0f01; Path=/; HttpOnly";
      "Strict-Transport-Security" = "max-age=31536000 ; includeSubDomains";
      "Www-Authenticate" = "Basic realm=\"DEEPFIELD\"";
      "X-Application-Context" = "gateway-dev:dev,cloud:0";
      "X-Cf-Requestid" = "b0f1e586-8b60-4413-646d-515dbbe1f097, 954fd628-3beb-4777-41be-4eb50221b808";
      "X-Content-Type-Options" = nosniff;
      "X-Frame-Options" = DENY;
      "X-Xss-Protection" = "1; mode=block";
  } }, NSLocalizedDescription=Expected status code in (200), got 401}
  2016-02-11 12:07:45.216 DeepField[7033:95645] E restkit.network:RKObjectRequestOperation.m:215 POST '<a href="https://myproject-dev.apps.mycompany-iot-cloud.com/api/v1/authenticate" rel="nofollow">https://myproject-dev.apps.mycompany-iot-cloud.com/api/v1/authenticate</a>' (401 Unauthorized / 0 objects) [request=0.9732s mapping=0.0000s total=0.9869s]: Error Domain=org.restkit.RestKit.ErrorDomain Code=-1011 "Expected status code in (200), got 401" UserInfo={NSLocalizedRecoverySuggestion={"timestamp":"2016-02-11T06:37:45.103+0000","status":401,"error":"Unauthorized","message":"Failed authenticating with username and password","path":"/api/v1/authenticate"}, NSErrorFailingURLKey=<a href="https://myproject-dev.apps.mycompany-iot-cloud.com/api/v1/authenticate" rel="nofollow">https://myproject-dev.apps.mycompany-iot-cloud.com/api/v1/authenticate</a>, AFNetworkingOperationFailingURLRequestErrorKey= { URL: <a href="https://myproject-dev.apps.mycompany-iot-cloud.com/api/v1/authenticate" rel="nofollow">https://myproject-dev.apps.mycompany-iot-cloud.com/api/v1/authenticate</a> }, AFNetworkingOperationFailingURLResponseErrorKey= { URL: <a href="https://myproject-dev.apps.mycompany-iot-cloud.com/api/v1/authenticate" rel="nofollow">https://myproject-dev.apps.mycompany-iot-cloud.com/api/v1/authenticate</a> } { status code: 401, headers {
      "Cache-Control" = "no-cache, no-store, max-age=0, must-revalidate";
      "Content-Length" = 171;
      "Content-Type" = "application/json;charset=UTF-8";
      Date = "Thu, 11 Feb 2016 06:37:44 GMT";
      Expires = 0;
      Pragma = "no-cache";
      Server = "";
      "Set-Cookie" = "<strong>VCAP_ID</strong>=7487ff5a5d1940b895d0459b91eaec009a55f1ebd2774084b28fc6d24cab0f01; Path=/; HttpOnly";
      "Strict-Transport-Security" = "max-age=31536000 ; includeSubDomains";
      "Www-Authenticate" = "Basic realm=\"myproject\"";
      "X-Application-Context" = "gateway-dev:dev,cloud:0";
      "X-Cf-Requestid" = "b0f1e586-8b60-4413-646d-515dbbe1f097, 954fd628-3beb-4777-41be-4eb50221b808";
      "X-Content-Type-Options" = nosniff;
      "X-Frame-Options" = DENY;
      "X-Xss-Protection" = "1; mode=block";
  } }, NSLocalizedDescription=Expected status code in (200), got 401}
  2016-02-11 12:07:45.216 DeepField[7033:94063] Error from server in Post Request</p>