Anushka Madushan
Anushka Madushan

Reputation: 681

Alamofire post request doesn't work?

I'm using alamofire latest version(swift 3), my pod installation like below,

pod 'Alamofire', :git => 'https://github.com/Alamofire/Alamofire.git', :branch => 'master'

And I'm trying to send a request as below, it worked for alamofire previous versions. However it doesn't work with this version.

In my opinion, the parameters are not sent properly.

 let param: Parameters = ["grant_type": "password",
                 "username": "0767898037",
                 "password" : "Hammer@123"]
    NSLog("param \(param))")
    Alamofire.request("http://api.xxxx.com/token" , method: .post, parameters: param , encoding: JSONEncoding.default).responseJSON { response in
        NSLog("res \(response.request))")
        switch response .result {

        case .success(let JSON) :
            NSLog("values \(response.result.value))")
            let response2 = JSON as! NSDictionary
             NSLog("values22 \(response2.value(forKeyPath: "access_token")))")
        case .failure(let error) :
            NSLog("errr \(response.result.value))")
            NSLog("error \(error))")
            let error = error as Error
            print(error.localizedDescription)
        }
    }

I'm getting an error in the console as follows:

2017-03-21 18:21:42.572362 com.sodesync.dudget.iOSClient[5927:1259497] values Optional({
error = "unsupported_grant_type";
}))

Upvotes: 0

Views: 515

Answers (1)

Kheldar
Kheldar

Reputation: 5389

Your server tells you that the grant type you provide (password) is not OK.

I would suggest testing your request via RESTed or Postman or curl.

Upvotes: 1

Related Questions