AFNetworking 2.0 POST request not working fast

I am facing a problem with AFNetworking 2.0 (coding in Swift). GET, the library seems to work fine for me. Although, the POST method returns me an error. Error: Invalid username / password. At first glance, that seems like an authentication problem, but actually when I tried the POST request on Postman (REST Client) worked fine.

So what I am doing:

Configuration:

var policy : AFSecurityPolicy = AFSecurityPolicy();
policy.allowInvalidCertificates = true;

self.client = AFHTTPRequestOperationManager(baseURL: self.basicUrl)
self.client!.operationQueue = NSOperationQueue.mainQueue()
self.client!.securityPolicy = policy

var responseSerializer : AFJSONResponseSerializer = AFJSONResponseSerializer()

self.client!.responseSerializer = responseSerializer

var requestSerializer : AFJSONRequestSerializer = AFJSONRequestSerializer()
requestSerializer.setValue("application/json", forHTTPHeaderField: "Accept")

self.client!.requestSerializer = requestSerializer

      

and my request

internal func loginUser(email : String, password : String, onCompletion : WebClientLoginResponse) -> Void
{
    var params : Dictionary = ["email":email, "pass":password]

    self.client!.POST("login", parameters: params, success: { (operation : AFHTTPRequestOperation!, response : AnyObject!) -> Void in

        var finalResponse : Dictionary = Dictionary<String, String>()

        finalResponse = response as Dictionary

        onCompletion(true, nil, nil, nil)

        }) { (operation : AFHTTPRequestOperation!, error : NSError!) -> Void in

            println("Error \(error.description) \(operation.responseObject) ")

            onCompletion(false, nil, nil, nil)
    }
}

      

What do you guys think? Did I miss something?

Thank!

+3


source to share


1 answer


Does your server require JSON encoded parameters? See the accepted answer to this question .



Also consider using the Swift version of AFNetworking, AlamoFire , which has an easier way (IMHO) to set the encoding format.

+2


source







All Articles