alamofire

How do I get at the underlying Error from an Alamofire error?

不想你离开。 提交于 2019-12-11 00:51:41
问题 For this request: Alamofire.request("https://google.com").responseCollection { (response: DataResponse<[User]>) in guard response.result.isSuccess else { print(response.error) return } } I see this printed in the console: Optional(my_app_name.BackendError.jsonSerialization(Alamofire.AFError.responseSerializationFailed(Alamofire.AFError.ResponseSerializationFailureReason.jsonSerializationFailed(Error Domain=NSCocoaErrorDomain Code=3840 "Invalid value around character 0." UserInfo=

Alamofire.AFError.ResponseSerializationFailureReason.jsonSerializationFailed(Error Domain=NSCocoaErrorDomain Code=3840

假装没事ソ 提交于 2019-12-11 00:49:40
问题 I am working on swift project and calling webservice with Alamofire. But, while calling post method, I am getting following error. Header file : let accessTokenHeaderFile = [ "Accept": "application/json", "Content-Type" :"application/json", "X-TOKEN" : UtilityClass.sharedInstance.accessTokenString ] Alamofire.request(urlString, method: .post, parameters: params as? [String:Any], encoding: JSONEncoding.default, headers: accessTokenHeaderFile).responseJSON { response in requestVC.removeLoader()

Swift (iOS), waiting for all images to finish downloading before returning

对着背影说爱祢 提交于 2019-12-11 00:47:12
问题 I am writing a Swift iOS app (my first, so please bear with me) where I use Swifter HTTP server to process various requests. One such request is an HTTP POST with a JSON array specifying images to download from the web (and do some other stuff, not pertinent to the issue at hand). I use Alamofire to download the images (this works fine), but I am looking for good (preferably simple) way to wait for all the images to finish downloading before returning a response to the POST request above

How to successfully pass string array as parameter alamofire

孤者浪人 提交于 2019-12-10 23:04:09
问题 I have an endpoint that accepts a string array as parameter but I can't get it working with alamofire. I test my endpoint with postman and it works fine, even in the browser, but with alamofire it fails and just returns the whole thing (as if I didn't put any parameter). func getQuotes(String url){ //THIS CALL IS NOT WORKING. PARAMETERS ARE NOT SENT PROPERLY - FIX let stringArray : [String] = ["4250_XSAU", "Test"] let getQuoteParameters : Parameters = [ //"internal_symbols":

Alamofire request stating extra argument for both parameters and method

。_饼干妹妹 提交于 2019-12-10 23:02:23
问题 After updating from swift 2.3 to 3, I have the following issue with NSMutableURLRequest in my Router class: var URLRequest: NSMutableURLRequest { let URL = Foundation.URL(string: Router.baseURLString)! let mutableURLRequest = NSMutableURLRequest(url: URL.appendingPathComponent(path)) mutableURLRequest.httpMethod = method.rawValue switch self { case .controlRequest(let a, let b, let c): let req : RegisterServer.Request = RegisterServer.Request() req.a = a req.b = b req.c = c let reqAsJsonStr =

Swift - closure expression syntax

你。 提交于 2019-12-10 22:46:19
问题 i'm working with Alamofire library, i've noticed that they use this syntax func download(method: Alamofire.Method, URLString: URLStringConvertible, headers: [String : String]? = default, #destination: Alamofire.Request.DownloadFileDestination) -> Alamofire.Request that takes 4 parameters as input but if you go to the documentation to call the method they use the following Alamofire.download(.GET, "http://httpbin.org/stream/100") { temporaryURL, response in let fileManager = NSFileManager

Int does not conform to protocol 'StringLiteralConvertible'

六月ゝ 毕业季﹏ 提交于 2019-12-10 20:46:38
问题 Im trying to parse json in weather app, but have hit a snag that i cannot get past. I do get an error, "Type 'int' does not conform to Protocol 'StringLiteralConvertible'" in the following code. Ive tried casting the jsonResult["main"] but that does instead give the error "Operand of postfix should have optional type, type is AnyObject". Do i need to downcast the Array in some way and how, if so, should i do that? I´ve searched so much for this but could not find any help in other posts. Code

RxSwift: onDisposed activated before Alamofire return data

♀尐吖头ヾ 提交于 2019-12-10 18:18:34
问题 I'm trying to get the JSON data from REST (swift 2.3) with rxSwift and Alamofire. This is my code: func getArticles(articlesReq: ArticlesReq) - > Observable < [Article] > { return Observable < [Article] > .create { observer in let request = Alamofire.request(.POST, apiPath, parameters: DataHelper().convertStringToDictionary(JSONString), encoding: .JSON) .responseArray { (response: Response < [Article], NSError > ) in if let articlesArray = response.result.value { observer.on(.Next

Alamofire post request with json encoding

限于喜欢 提交于 2019-12-10 18:09:43
问题 How to send a post request with Alamofire with parameters as json having list of integers i.e, my server expects a dictionary whose value for the key is a list of integers. I want the parameters as {"abc":[1,2,3]}. How to send this along post request of Alamofire in swift? 回答1: Have you tried the following? var parameter = ["abc": [1,2,3]] Alamofire.request(.POST, "http://www.yoursite.com/api" , parameters:parameter) I would also look at the documentation over at Alamofire github

Alamofire: file download and validation failure

徘徊边缘 提交于 2019-12-10 18:07:34
问题 In my iOS project I'm using Alamofire library to download remote documents (from a server with Basic Auth) in this way: let destination: DownloadRequest.DownloadFileDestination = { _, _ in let documentsURL = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)[0] let fileURL = documentsURL.appendingPathComponent("foo.pdf") return (filePath.url, [.removePreviousFile, .createIntermediateDirectories]) } Alamofire.download(myUrlRequest, to: destination).authenticate(user: user,