Swift - 服务器响应" unsupported_grant_type"

时间:2016-07-29 19:46:44

标签: ios swift alamofire

我尝试使用alamofire登录。 即时通讯使用以下代码:

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)
            }
        }

服务器响应如下:

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

原因可能是什么?我错过了什么吗?

我很高兴实现连接到服务器的应用程序。

据我所知,服务器使用Django和REST框架以及oAuth2。

我希望得到足够的帮助。我试图搜索很多关于这个问题以及如何解决它但没有运气。

提前感谢。

1 个答案:

答案 0 :(得分:0)

调试核对清单

  1. 您是否在网址中使用了https?

  2. 您的服务器是否具有来自证书颁发机构的服务器证书注意iOS 9不会连接到自签名 证书)?

  3. 您是否使用像“SwiftyJSON”对象模型的对象maper到json
  4. 不是错误按摩我想你必须检查你的帖子网址或服务器证书

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