Custom-encoded Alamofire for quick application

I need to call some methods from a soapy web service in my quick application, so I think I should use a special parameter encoding, but when I create a closure for this encoding, it seems to never be called. Am I doing something wrong?

Here is my code:

    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)
    }
+4
source share
1 answer

Closing is customnot performed by design because there are no parameters for encoding. This is a piece of code taken from the source file Alamofire.swift :

if parameters == nil {
    return (URLRequest.URLRequest, nil)
}

As you can see, you can pass this condition by passing an empty dictionary:

Alamofire.request(.POST, WebServiceURLString, parameters: Dictionary(), encoding: .Custom(custom))

custom.

+4

All Articles