Swift Sending Boolean Values in Alamofire Params

In my app I need to send Boolean values inside alamofire params. Here is the code

var SearchParams = [String:Any]()
SearchParams["id"] = "125"
SearchParams["my_case"] = false

But in server end boolean value received as String. I have tried in multiple ways like

var SearchParams: [String:Anyobject]?
SrearchParams = ["id":"125","my_case": false]

var SearchParams = [String:AnyObject]()
SearchParams["id"] = "125" as AnyObject
SearchParams["my_case"] = false as AnyObject

But It Wont Works.

You can use NSNumber class for passing boolean value. Like following code

SearchParams["my_case"] = NSNumber(value: false)

This will help you

Sending Bool params � Issue #1038 � Alamofire/Alamofire � GitHub, When creating a boolean param swift will automatically convert it to 0 or Now, if the server has some validation and expects a Boolean value� Alamofire has its own support for HTTP Headers which are a great way to let the client and the server pass additional information with an HTTP request or response. It can be easily added to our Alamofire Request easily by just adding an HTTPHeaders value:

Code Here:

var SearchParams = [String:Any]()
SearchParams["id"] = "\(self.SelectedId)"
SearchParams["my_case"] = false as Bool
let fileUrl = Foundation.URL(string: baseurl)
var request = URLRequest(url: fileUrl!)
request.httpMethod = "POST"
request.setValue("application/json", forHTTPHeaderField: "Content-Type")
request.allHTTPHeaderFields = ["FirmUserId": "\(self.FirmUserId)", "Authorization": "Token token=\(self.AuthToken)","UserId":"\(self.UserId)"]
request.httpBody = try! JSONSerialization.data(withJSONObject: SearchParams, options: .prettyPrinted)
Alamofire.request(request).responseJSON { response in

Bool in URL encoded parameters encodes as 0 and 1 � Issue #1056 , Alamofire.request(endpoint.method(), url, parameters: parameters, encoding: I' m using Swift 2 in XCode 7.2.1 with a mixed codebase. It doesn't seem to be possible to accomplish bools sent as "true" and "false" in a URL� Alamofire is a Swift-based HTTP networking library for iOS and macOS. It provides an elegant interface on top of Apple’s Foundation networking stack that simplifies a number of common networking tasks. Alamofire provides chainable request/response methods, JSON parameter and response serialization, authentication, and many other features.

This will work

var SearchParams= ["id":"123","iSActive": false] as [String : Any]

Swift Sending Boolean Values in Alamofire Params, In my app I need to send Boolean values inside alamofire params. Here is the code var SearchParams = [String:Any]()SearchParams["id"]� //Extend Alamofire so it can do POSTs with a JSON body from passed object extension Alamofire.Manager { public class func request( method: Alamofire.Method, _ URLString: URLStringConvertible, bodyObject: EVObject) -> Request { return Manager.sharedInstance.request( method, URLString, parameters: [:], encoding: .Custom({ (convertible, params) in

This helped me

var SearchParams= ["id":"123","iSActive": false] as [String : Any]

Alamofire 5 Tutorial for iOS: Getting Started, In this Alamofire tutorial, you'll build an iOS companion app to of data types to choose from: string, boolean, array, object/dictionary, number and null. It can accept more parameters, but for now, you'll just send the URL as� Using Imported Boolean values. The C bool and Boolean types and the Objective-C BOOL type are all bridged into Swift as Bool. The single Bool type in Swift guarantees that functions, methods, and properties imported from C and Objective-C have a consistent type interface.

Alamofire Tutorial: Getting Started, Alamofire is a Swift-based HTTP networking library for iOS and macOS. HEAD: Identical to GET but only sends back the headers and none of the actual data. JSON has a limited number of data types: string, boolean, array, return } Alamofire.request(url, method: .get, parameters: ["include_docs":� The `URLEncoding.BoolEncoding` enumeration provides the following methods for encoding `Bool` parameters: - `.numeric` - Encode `true` as `1` and `false` as `0`. - `.literal` - Encode `true` and `false` as string literals. By default, Alamofire uses the `.numeric` encoding.

Encode Swift array for Alamofire post using URLEncoding, Encode Swift array for Alamofire post using URLEncoding. alamofire However the parameters never get encoded and just get sent as nil. How can I BoolEncoding can be used to configure how boolean values are encoded. The default� json - example - swift post request with parameters How to send a POST request with BODY in swift (7) I'm trying to make a post request with a body in swift using Alamofire.

Alamofire, [x] Chainable Request / Response Methods; [x] URL / JSON / plist Parameter Encoding is as easy as adding it to the dependencies value of your Package. swift . The build target for Alamofire will be listed as either Alamofire iOS , Alamofire When sending relatively small amounts of data to a server using JSON or URL� Alamofire’s request can accept more than just the URL string that you’ve sent so far. It can also accept an array of key/value pairs as parameters. The swapi.dev API allows you to send parameters to the starships endpoint to perform a search. To do this, you use a key of search with the search criteria as the value.

  • Try sending 0 or 1 for Boolean purpose