简体   繁体   English

使用AlamoFire的Json请求

[英]Json Request Using AlamoFire

This is my Json request 这是我的杰森要求

var postsEndpoint = "http://test/Search"

let test = ["SearchCriteria":["ForeName":"jack", "Surname":"jill"]];


    request(.POST, postsEndpoint, parameters: test, encoding: .JSON)
        .responseJSON { (request, response, data, error) in
            if let anError = error
            {
                println("error calling POST on /posts")
                println(error)
            }
            else if let data: AnyObject = data
            {

                let post = JSON(data)
                println("The post is: " + post.description)
            }

Is there an issue with my request as I am getting the following error: 我收到以下错误时,我的请求是否有问题:

error calling POST on /posts Optional(Error Domain=NSCocoaErrorDomain Code=3840 "The operation couldn't be completed. (Cocoa error 3840.)" (Invalid value around character 3.) UserInfo=0x7fdd00414c80 {NSDebugDescription=Invalid value around character 3.}) 在/ posts上调用POST时出错可选(错误域= NSCocoaErrorDomain代码= 3840“操作无法完成。(可可错误3840。)”(字符3周围的无效值。)UserInfo = 0x7fdd00414c80 {NSDebugDescription =字符3周围的无效值。})

Late, but I found this thread. 迟了,但是我找到了这个线程。

I ran into this same problem running a Django dev server and got You called this URL via POST, but the URL doesn't end in a slash and you have APPEND_SLASH set. Django can't redirect to the slash URL while maintaining POST data. 我在运行Django开发服务器时遇到了同样的问题,并让You called this URL via POST, but the URL doesn't end in a slash and you have APPEND_SLASH set. Django can't redirect to the slash URL while maintaining POST data. You called this URL via POST, but the URL doesn't end in a slash and you have APPEND_SLASH set. Django can't redirect to the slash URL while maintaining POST data.

Append a slash to postsEndpoint so it becomes... postsEndpoint一个斜线,使其变为...
var postsEndpoint = "http://test/Search"

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

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