我在解决Swift Alamofire POST请求(登录用户)时遇到此错误消息.
I am having trouble fixing this error message on my Swift Alamofire POST request (to login a user).
'3840'字符1周围的值无效".
'3840' "Invalid value around character 1."
我已经导入了Foundation, Alamofire , SwiftyJson .没有授权限制(没有Oauth等).更改Post(例如,使用其他参数和值的另一个端点)但将其余代码/格式保持不变时,我也收到相同的错误消息.在我的drupal7 REST服务器的'definitions'上,它将端点列出为/rest/user/login,并将参数列出为'username'和'password'字符串(如我所用).
I have imported Foundation, Alamofire, SwiftyJson. There are no authorisation restrictions (no Oauth etc). I'm also getting the same error message when I change the Post (eg to another endpoint, with other parameters and values) but keep the rest of the code/format the same. On my drupal7 REST server 'definitions' it lists the endpoint as /rest/user/login and parameters as 'username' and 'password' strings as I've used.
我真的很感谢任何提示和帮助吗?
I'd really appreciate any tips and help?
调用REQUEST时出错 错误域= NSCocoaErrorDomain代码= 3840字符1周围的值无效." UserInfo = {NSDebugDescription =字符1周围的值无效.}
error calling REQUEST Error Domain=NSCocoaErrorDomain Code=3840 "Invalid value around character 1." UserInfo={NSDebugDescription=Invalid value around character 1.}
这是我的代码
@IBAction func loginButtonTapped(sender: AnyObject) { //using Alamofire let dataEndpoint: String = "www.example/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) } }谢谢
推荐答案在URL端点的末尾添加.json已解决了该错误.即 www.example/rest/user/login.json
Adding .json at the end of the URL endpoint has solved the error. ie www.example/rest/user/login.json
更多推荐
快速错误"Domain = NSCocoaErrorDomain Code = 3840"“字符1周围的无效值".
发布评论