带有afnetworking的Swift post数组

时间:2015-07-03 14:20:45

标签: ios arrays swift post afnetworking

我想发布一些数字和其他参数,但我收到错误信息

{ error = "The operation couldn\U2019t be completed. (Cocoa error 3840.)"; }

这是我正在尝试的,在我的api控制器中

func postRequest(url: String, params: NSDictionary, callback:(NSDictionary) -> ()) {

    manager.responseSerializer.acceptableContentTypes = NSSet(array: ["text/plain", "text/html", "application/json"]) as Set<NSObject>

    manager.POST(url, parameters: params,
    success: { (operation: AFHTTPRequestOperation!,responseObject: AnyObject!) in
        //println("JSON: " + responseObject.description)
        callback(responseObject as! NSDictionary)
    },
    failure: { (operation: AFHTTPRequestOperation!,error: NSError!) in
        //println("Error: " + error.localizedDescription)
        callback(["error" : error.localizedDescription])
    })
}

然后在我的视图控制器中,我发布

    var contacts = ["xxxxxxxx", "xxxxxxxx", "xxxxxxxx"]
    var params = ["id" : 1, "contacts" :  contacts ]
    api.postRequest(Constants.ApiUrl.Friends, params: params, callback: { (response) -> () in
        //self.didReceiveResponse(response)
        println(response)
    })

请问我该怎么做这个帖子

0 个答案:

没有答案