【问题标题】:Json Request Using AlamoFire使用 AlamoFire 的 Json 请求
【发布时间】:2015-07-26 17:37:53
【问题描述】:

这是我的 Json 请求

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

我的请求是否存在问题,因为我收到以下错误:

在 /posts 上调用 POST 时出错 可选(错误域=NSCocoaErrorDomain Code=3840“操作无法完成。(Cocoa 错误 3840。)”(字符 3 周围的值无效。) UserInfo=0x7fdd00414c80 {NSDebugDescription=字符 3 周围的值无效)

【问题讨论】:

  • 错误说明了问题所在:您返回的响应不是有效的 JSON。使用responseString 记录字符串表示以查看问题所在。

标签: json alamofire


【解决方案1】:

晚了,但我找到了这个帖子。

我在运行 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.

postsEndpoint 后面加上一个斜杠,这样它就变成了...
var postsEndpoint = "http://test/Search"

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-03-20
    • 1970-01-01
    • 1970-01-01
    • 2019-07-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多