How to add Alamofire URL parameters

The problem is that you’re using URLEncoding.default. Alamofire interprets URLEncoding.default differently depending on the HTTP method you’re using. For GET, HEAD, and DELETE requests, URLEncoding.default encodes the parameters as a query string and adds it to the URL, but for any other method (such as POST) the parameters get encoded as a query string and … Read more

SSL_ERROR_SSL(1): operation failed within the library

Deadlock I assume spotifyRequest will be called on the main thread. So if the main thread reaches the line group.wait() and this line of responseJSON completionHandler was not called yet: group.leave() then the main thread is blocked due to the call of group.wait() above. Due to the blocked main thread group.leave() can’t be called. Classical … Read more

Swift 3 Alamofire multipart upload

For example, using Alamofire 4.0.0 in Swift 3: (make sure you are 4.0.0 ready as it looks like you haven’t updated your Alamofire yet) Alamofire.upload(multipartFormData: { (multipartFormData) in // code }, to: URL, encodingCompletion: { (result) in // code }) or Alamofire.upload(multipartFormData: { (multipartFormData) in // code }, with: URL, encodingCompletion: { (result) in // … Read more

upload image to server using Alamofire

Try below code let image = UIImage.init(named: “myImage”) let imgData = UIImageJPEGRepresentation(image!, 0.2)! let parameters = [“name”: rname] //Optional for extra parameter Alamofire.upload(multipartFormData: { multipartFormData in multipartFormData.append(imgData, withName: “fileset”,fileName: “file.jpg”, mimeType: “image/jpg”) for (key, value) in parameters { multipartFormData.append(value.data(using: String.Encoding.utf8)!, withName: key) } //Optional for extra parameters }, to:”mysite/upload.php”) { (result) in switch result { … Read more

Handle timeout with Alamofire

You can compare error._code and if it is equal to -1001 which is NSURLErrorTimedOut then you know this was a timeout. let manager = Alamofire.SessionManager.default manager.session.configuration.timeoutIntervalForRequest = 120 manager.request(“yourUrl”, method: .post, parameters: [“parameterKey”: “value”]) .responseJSON { response in switch (response.result) { case .success: // succes path case .failure(let error): if error._code == NSURLErrorTimedOut { print(“Request … Read more

Chain multiple Alamofire requests

Wrapping other asynchronous stuff in promises works like this: func myThingy() -> Promise<AnyObject> { return Promise{ fulfill, reject in Alamofire.request(.GET, “http://httpbin.org/get”, parameters: [“foo”: “bar”]).response { (_, _, data, error) in if error == nil { fulfill(data) } else { reject(error) } } } } Edit: Nowadays, use: https://github.com/PromiseKit/Alamofire-

How to disable caching in Alamofire

You have a few options. Disabling the URLCache Completely let manager: Manager = { let configuration = NSURLSessionConfiguration.defaultSessionConfiguration() configuration.URLCache = nil return Manager(configuration: configuration) }() Configuring the Request Cache Policy let manager: Manager = { let configuration = NSURLSessionConfiguration.defaultSessionConfiguration() configuration.requestCachePolicy = .ReloadIgnoringLocalCacheData return Manager(configuration: configuration) }() Both approaches should do the trick for you. For … Read more

Alamofire Swift 3.0 Extra argument in call

According to Alamofire documentation for version 4.0.0 URL request with HTTP method would be followings: Alamofire.request(“https://httpbin.org/get”) // method defaults to `.get` Alamofire.request(“https://httpbin.org/post”, method: .post) Alamofire.request(“https://httpbin.org/put”, method: .put) Alamofire.request(“https://httpbin.org/delete”, method: .delete) So your url request will be: Alamofire.request(patientIdUrl, method: .post, parameters: nil, encoding: JSONEncoding.default, headers: nil) and a sample request will be: Alamofire.request(url, method: .post, parameters: … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)