简体   繁体   English

Alamofire POST请求错误NSURLErrorDomain代码= -999

[英]Alamofire POST request ERROR NSURLErrorDomain Code=-999

I'm working on login in my project and I'm using Alamofire request (swift 2.0) and I always get an error that I can't resolve. 我正在我的项目中登录,并且正在使用Alamofire请求(swift 2.0),但总是收到无法解决的错误。

Error Domain=NSURLErrorDomain Code=-999 "cancelled" UserInfo=... {NSErrorFailingURLKey=..., NSLocalizedDescription=cancelled, NSErrorFailingURLStringKey=...} 错误域= NSURLErrorDomain代码= -999“已取消” UserInfo = ... {NSErrorFailingURLKey = ...,NSLocalizedDescription =已取消,NSErrorFailingURLStringKey = ...}

Here is my code: 这是我的代码:

func login(email: String, password: String, completionHandler: (user: User?, statusCode: Int?, error: NSError?) -> ()) {
    let parameters: [String: AnyObject] = [
        "email" : email,
        "password" : password
    ]


    let urlSuffix = "loginUser"


     request(.POST, baseUrl + urlSuffix, parameters: parameters)
        .authenticate(user: email, password: password)
        .validate()
        .responseObject { (request, response, userJSON: Result<User>) in
            print(request?.description)
            print(response)
            print(userJSON.value)
            completionHandler(user: userJSON.value, statusCode: response?.statusCode, error: userJSON.error)
        }


}

I call that function in my LoginController, when user press a button. 当用户按下按钮时,我在LoginController中调用该函数。

I passed through many posts about that error, but none of them gave me a solution. 我浏览了许多有关该错误的帖子,但没有一个给我解决方案。 The problem is, I need the response, a JSON object witch contains user's id. 问题是,我需要响应,一个JSON对象包含用户的ID。 But my Result<User> is nil due to the error. 但是由于错误,我的Result<User>为nil。

问题已解决,我将错误的变量传递给.authenticate()他们应该与我的参数(email, password)

确保您的baseUrl使用HTTPS协议或对该域禁用“应用程序传输安全性”。

The -999 clue is "cancelled." -999提示已“取消”。 Your connection isn't permitted. 不允许您的连接。 One possible reason is that you're trying to establish an SSL connection but the client does not trust the SSL certificate. 一个可能的原因是您试图建立SSL连接,但是客户端不信任SSL证书。

If this is a development system with a self-signed certificate, you'll need to set allowsInvalidSSLCertificate . 如果这是具有自签名证书的开发系统,则需要设置allowsInvalidSSLCertificate

Otherwise, check SSL pinning. 否则,请检查SSL固定。 It's enabled by default, which means you may need to preload your certificate for the server to be trusted. 默认情况下已启用它,这意味着您可能需要预加载证书才能使服务器可信。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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