alamofire

How to send a POST request with BODY in swift

旧街凉风 提交于 2019-11-26 02:33:18
问题 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

How to parse JSON response from Alamofire API in Swift?

雨燕双飞 提交于 2019-11-26 02:18:56
问题 Following code I have written and I am getting response in JSON also but the type of JSON is \"AnyObject\" and I am not able to convert that into Array so that I can use that. Alamofire.request(.POST, \"MY URL\", parameters:parameters, encoding: .JSON) .responseJSON { (request, response, JSON, error) in println(JSON?) } 回答1: The answer for Swift 2.0 Alamofire 3.0 should actually look more like this: Alamofire.request(.POST, url, parameters: parameters, encoding:.JSON).responseJSON { response

Uploading file with parameters using Alamofire

喜你入骨 提交于 2019-11-25 23:53:51
问题 I am attempting to upload a file using Alamofire . The upload works fine when using a File ( NSUrl ), however, I cant seem to figure out how to use the NSData option? This is what I have as a test: var url:NSURL = NSURL.URLWithString(\"http://localhost:8080/bike.jpeg\") var err: NSError? var imageData :NSData = NSData.dataWithContentsOfURL(url,options: NSDataReadingOptions.DataReadingMappedIfSafe, error: &err) Alamofire.upload(.POST, \"http://localhost:8080/rest/service/upload/test.png\",

How to return value from Alamofire

与世无争的帅哥 提交于 2019-11-25 22:59:02
问题 I am making url calls thru an API that I created using swift as follows: class API { let apiEndPoint = \"endpoint\" let apiUrl:String! let consumerKey:String! let consumerSecret:String! var returnData = [:] init(){ self.apiUrl = \"https://myurl.com/\" self.consumerKey = \"my consumer key\" self.consumerSecret = \"my consumer secret\" } func getOrders() -> NSDictionary{ return makeCall(\"orders\") } func makeCall(section:String) -> NSDictionary{ let params = [\"consumer_key\":\"key\", \