alamofire

Send POST parameters with MultipartFormData using Alamofire, in iOS Swift

爱⌒轻易说出口 提交于 2019-11-26 15:52:17
I am using Alamofire, very first time. I am using the latest version Alamofire 1.3.1. I want to send one image , one video and some POST parameters in one API call. I am using multipart form data. The mutipart module is working. I am facing a problem to send extra POST parameters params . Below is my code. "params" is the dictionary which contains extra parameters? How can I append these POST parameters in the request. Please help var fullUrl :String = Constants.BASE_URL + "/api/CompleteChallenge" var params = [ "authKey": Constants.AuthKey, "idUserChallenge": "16", "comment": "", "photo":

AlamoFire Download in Background Session

时光怂恿深爱的人放手 提交于 2019-11-26 15:27:35
问题 I am using Alamofire within a new app (A Download Manager Sample based on Alamofire) I need some clarifications about downloading files using the background session. I need to override SessionDelegate to get it works? Or just backgroundCompletionHandler ? Typically what are the steps to handle downloads in background using Alamofire? And how can I handle the case where my app is relauch, with downloads in flux. 回答1: Update Based on this amazing tutorial, I have put together an example project

Alamofire Swift 3.0 Extra argument in call

微笑、不失礼 提交于 2019-11-26 15:18:21
I have migrated my project to Swift 3 (and updated Alamofire to latest Swift 3 version with pod 'Alamofire', '~> 4.0' in the Podfile). I now get an "Extra argument in call" error on every Alamofire.request. Eg: let patientIdUrl = baseUrl + nextPatientIdUrl Alamofire.request(.POST, patientIdUrl, parameters: nil, headers: nil, encoding: .JSON) Can anybody tell me why ? 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",

How to check internet connection in alamofire?

浪子不回头ぞ 提交于 2019-11-26 12:09:32
问题 I am using below code for making HTTP request in server.Now I want to know whether it is connected to internet or not. Below is my code let request = Alamofire.request(completeURL(domainName: path), method: method, parameters: parameters, encoding: encoding.value, headers: headers) .responseJSON { let resstr = NSString(data: $0.data!, encoding: String.Encoding.utf8.rawValue) print(\"error is \\(resstr)\") if $0.result.isFailure { self.failure(\"Network\") print(\"API FAILED 4\") return }

How to send a POST request with BODY in swift

孤街浪徒 提交于 2019-11-26 11:43:21
I'm trying to make a post request with a body in swift using Alamofire. my json body looks like : { "IdQuiz" : 102, "IdUser" : "iosclient", "User" : "iosclient", "List":[ { "IdQuestion" : 5, "IdProposition": 2, "Time" : 32 }, { "IdQuestion" : 4, "IdProposition": 3, "Time" : 9 } ] } I'm trying to make let list with NSDictionnary which look like : [[Time: 30, IdQuestion: 6510, idProposition: 10], [Time: 30, IdQuestion: 8284, idProposition: 10]] and my request using Alamofire looks like : Alamofire.request(.POST, "http://myserver.com", parameters: ["IdQuiz":"102","IdUser":"iOSclient","User":

Downloading UIImage via AlamofireImage? [duplicate]

雨燕双飞 提交于 2019-11-26 11:37:24
问题 This question already has answers here : How can I get the Data from NSURLSession.sharedSession().dataTaskWithRequest (2 answers) Closed 2 years ago . I have a URL and want to download the image via a return function, however I cant get it to cooperate properly, here is my func: func getTabImage(url: URL) -> UIImage { Alamofire.request(url) .responseImage { response in if let image = response.result.value { return image } else { print(\"Failed to get image\") } } } I pass in the URL, and want

Sending json array via Alamofire

六月ゝ 毕业季﹏ 提交于 2019-11-26 11:21:49
I wonder if it's possible to directly send an array (not wrapped in a dictionary) in a POST request. Apparently the parameters parameter should get a map of: [String: AnyObject]? But I want to be able to send the following example json: [ "06786984572365", "06644857247565", "06649998782227" ] You can just encode the JSON with NSJSONSerialization and then build the NSURLRequest yourself. For example, in Swift 3: var request = URLRequest(url: url) request.httpMethod = "POST" request.setValue("application/json", forHTTPHeaderField: "Content-Type") let values = ["06786984572365", "06644857247565",

Getting client certificate to work for mutual authentication using Swift 3 and Alamofire 4

…衆ロ難τιáo~ 提交于 2019-11-26 11:14:56
问题 I am trying to figure out how to use Alamofire 4.0 with Swift 3.0 to send a p12 (i also have the PEM cert and key if need be) to a website for authentication. All the examples i have seen are for Swift 2.0 and not exactly what i\'m looking for. In safari on my mac i can access the site by putting the p12 in the keychain and sending it when safari asks so i know that portion works. I don\'t know if anyone can help me with an example of how to do so in Alamofire 4.0 and Swift 3.0 in an

How to post nested json by SwiftyJson and Alamofire?

隐身守侯 提交于 2019-11-26 10:00:08
问题 How to post nested json like below as body of method by SwiftyJson and Alamofire?(Swift 3) { \"a\":{ \"a1\": \"v1\", \"a2\": \"v2\" }, \"b\":\"bv\" } I check lots of post Json post nested objects in swift using alamofire , How do I access a nested JSON value using Alamofire and SwiftyJSON? , Alamofire JSON Serialization of Objects and Collections and ... but none of them helped for this situation. 回答1: try this func test() { var exampleParameters : [String : Any] = ["b" : "bv"]

How to disable caching in Alamofire

自古美人都是妖i 提交于 2019-11-26 09:34:37
问题 When I send a GET request twice with Alamofire I get the same response but I\'m expecting a different one. I was wondering if it was because of the cache, and if so I\'d like to know how to disable it. 回答1: swift 3, alamofire 4 My solution was: creating extension for Alamofire: extension Alamofire.SessionManager{ @discardableResult open func requestWithoutCache( _ url: URLConvertible, method: HTTPMethod = .get, parameters: Parameters? = nil, encoding: ParameterEncoding = URLEncoding.default,