本文介绍了具有自定义参数编码的Alamofire,可快速应用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我必须在我的swift应用程序中从soap Web服务调用一些方法,所以我认为我应该使用自定义参数编码,但是当我为这种编码创建闭包时,似乎永远都不会被调用。我在做错什么吗?
I have to call some methods from the soap web service in my swift application, so I think I should use custom parameter encoding, but when I create closure for this encoding it seems never to be called. Am I doing something wrong?
这是我的代码:
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) }中的空
推荐答案自定义闭包不是设计执行的,因为没有要编码的参数。他是从 Alamofire.swift源文件中摘录的代码:
The custom closure is not executed by design, because there are no parameters to encode. He're a code excerpt taken from Alamofire.swift source file:
if parameters == nil { return (URLRequest.URLRequest, nil) }如您所见,可以通过传递空字典来消除这种情况:
As you can see, you can bybass this condition by passing an empty dictionary:
Alamofire.request(.POST, WebServiceURLString, parameters: Dictionary(), encoding: .Custom(custom))自定义闭包现在将被执行。
更多推荐
具有自定义参数编码的Alamofire,可快速应用
发布评论