【发布时间】:2016-08-28 01:52:24
【问题描述】:
我无法在我的 Swift Alamofire POST 请求中修复此错误消息(以登录用户)。
'3840' "字符 1 周围的值无效。"
我已经导入了 Foundation、Alamofire、SwiftyJson。没有授权限制(没有 Oauth 等)。当我更改 Post(例如,使用其他参数和值到另一个端点)但保持其余代码/格式相同时,我也会收到相同的错误消息。在我的 drupal7 REST 服务器“定义”上,它将端点列为 /rest/user/login,将参数列为我使用的“用户名”和“密码”字符串。
非常感谢任何提示和帮助?
调用请求时出错 错误域 = 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)
}
}
谢谢
【问题讨论】:
-
只是表示你得到的 JSON 响应是无效的(或者不是 JSON)。
标签: swift post error-handling alamofire