我必须在我的 swift 应用程序中从 SOAP Web 服务调用一些方法,所以我认为我应该使用自定义参数编码,但是当我为此编码创建闭包时,它似乎永远不会被调用。难道我做错了什么?
这是我的代码:
let custom: (URLRequestConvertible, [String: AnyObject]?) -> (NSURLRequest, NSError?) = {
(URLRequest, parameters) in
let mutableURLRequest = URLRequest.URLRequest.mutableCopy() as NSMutableURLRequest
mutableURLRequest.setValue("text/xml; charset=utf-8", forHTTPHeaderField: "Content-Type")
mutableURLRequest.HTTPBody = body
return (mutableURLRequest, nil)
}
Alamofire.request(.POST, WebServiceURLString, parameters: nil, encoding: .Custom(custom)).responseString { (request, response, data, error) -> Void in
println(data)
}
The custom
闭包不是按设计执行的,因为没有要编码的参数。他的代码摘录自Alamofire.swift 源文件 https://github.com/Alamofire/Alamofire/blob/master/Source/Alamofire.swift#L78-80:
if parameters == nil {
return (URLRequest.URLRequest, nil)
}
正如您所看到的,您可以通过传递一个空字典来绕过这种情况:
Alamofire.request(.POST, WebServiceURLString, parameters: Dictionary(), encoding: .Custom(custom))
The custom
现在将执行关闭。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)