简体   繁体   中英

Swift - Server response “unsupported_grant_type”

I'm trying to login using alamofire. im using the following code:

let parameters = [
            "username": "2gggggjggg",
            "password": "2ubgh",
        ]
        Alamofire.request(.POST, URL , parameters: parameters, encoding: .JSON).responseJSON { response in
            print("request")
            print(response.request)  // original URL request
            print("response")
            print(response.response) // URL response
            print("data")
            print(response.data)     // server data
            print("result")
            print(response.result)   // result of response serialization
            print("JSON")
            if let JSON = response.result.value {
                print("JSON: \(JSON)")
            }
            if let myData = response.data?.base64EncodedStringWithOptions(.Encoding64CharacterLineLength) {
                SignUpVC.clientID = myData
                print(myData)
            }
        }

the server response as follows:

data
Optional(<7b226572 726f7222 3a202275 6e737570 706f7274 65645f67 72616e74 5f747970 65227d>)
result
SUCCESS
JSON
JSON: {
    error = "unsupported_grant_type";
}

what might the reason be? am i missing anything?

im new to implementing apps that connects to a server.

as far as i know the server uses Django with REST framework and oAuth2.

i hope to get enough help about it. I've tried to search a lot about this problem and how to resolve it but no luck.

thanks in advance.

Debugging check list

  1. Did you use https in your url?

  2. Did your server have Server Certificate from Certification authority Note iOS 9 will not connected to self sign Certificate)?

  3. Do you use object maper like "SwiftyJSON" object Model to json

not from the error massage I think you have to check your post url or you Server Certificate

let URL:String ="https://youURLHere"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM