迅速错误“ Domain = NSCocoaErrorDomain代码= 3840”字符1周围的值无效。

Dim*_*i T 5 error-handling post swift alamofire

我无法在我的Swift Alamofire POST请求(登录用户)上修复此错误消息。

3840字符1周围的值无效。

我已经导入了Foundation,AlamofireSwiftyJson。没有授权限制(没有Oauth等)。更改Post(例如,使用其他参数和值的另一个端点),但其余代码/格式保持不变时,我也收到相同的错误消息。在我的drupal7 REST服务器的'definitions'上,它将端点列为/ rest / user / login,并将参数列为'username'和'password'字符串(如我所用)。

我真的很感谢任何提示和帮助?

调用REQUEST时出错,错误域= NSCocoaErrorDomain代码= 3840“字符1周围的值无效”。UserInfo = {NSDebugDescription =字符1周围的值无效。}

这是我的代码

 @IBAction func loginButtonTapped(sender: AnyObject) {

    //using Alamofire

    let dataEndpoint: String = "https://www.example.com/rest/user/login"
    let newData = ["username":"Mickey", "password":"123"]
    Alamofire.request(.POST, dataEndpoint, parameters: newData, encoding: .JSON)
        .responseJSON { response in
            guard response.result.error == nil else {
                // got an error in posting the data, need to handle it
                print("error calling REQUEST")
                print(response.result.error!)
                return
            }

            guard let value = response.result.value else {
                print("no result data  when calling request")
                return
            }
            let data = JSON(value)
            print("The result is: " + data.description)
    }

}
Run Code Online (Sandbox Code Playgroud)

谢谢

Dim*_*i T 1

在 URL 端点末尾添加 .json 解决了该错误。即https://www.example.com/rest/user/login.json