2
votes

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.})

1
The error says exactly what's wrong: the response you're getting back isn't valid JSON. Use responseString to log the string representation to see what's the matter. - mattt

1 Answers

0
votes

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.

Append a slash to postsEndpoint so it becomes...
var postsEndpoint = "http://test/Search"