alamofire

alamofire.error Code=-6006 "JSON could not be serialized

心不动则不痛 提交于 2019-12-28 04:18:08
问题 Been working on this for a bit with no success. I have a function that goes to a UIButton solely to perform alamofire calls to my rails api which uses all JSON. I'm using Swift 2, Alamofire 3, XCode 7 & Rails 4 for my api which is deployed to Heroku I keep getting this error when I fire off the function : alamofire.error Code=-6006 "JSON could not be serialized. Input data was nil or zero length. Here is my code : @IBAction func Save(sender: AnyObject) { let postsEndpoint: String = "https:/

Swift Alamofire: How to get the HTTP response status code

孤者浪人 提交于 2019-12-28 03:20:15
问题 I would like to retrieve the HTTP response status code (e.g. 400, 401, 403, 503, etc) for request failures (and ideally for successes too). In this code, I am performing user authentication with HTTP Basic and want to be able to message the user that authentication failed when the user mistypes their password. Alamofire.request(.GET, "https://host.com/a/path").authenticate(user: "user", password: "typo") .responseString { (req, res, data, error) in if error != nil { println("STRING Error::

POST request with a simple string in body with Alamofire

情到浓时终转凉″ 提交于 2019-12-27 11:11:54
问题 how is it possible to send a POST request with a simple string in the HTTP body with Alamofire in my iOS app? As default Alamofire needs parameters for a request: Alamofire.request(.POST, "http://mywebsite.com/post-request", parameters: ["foo": "bar"]) These parameters contain key-value-pairs. But I don't want to send a request with a key-value string in the HTTP body. I mean something like this: Alamofire.request(.POST, "http://mywebsite.com/post-request", body: "myBodyString") 回答1: Your

POST request with a simple string in body with Alamofire

≯℡__Kan透↙ 提交于 2019-12-27 11:11:33
问题 how is it possible to send a POST request with a simple string in the HTTP body with Alamofire in my iOS app? As default Alamofire needs parameters for a request: Alamofire.request(.POST, "http://mywebsite.com/post-request", parameters: ["foo": "bar"]) These parameters contain key-value-pairs. But I don't want to send a request with a key-value string in the HTTP body. I mean something like this: Alamofire.request(.POST, "http://mywebsite.com/post-request", body: "myBodyString") 回答1: Your

How to get data from JSON response in iOS Swift?

六眼飞鱼酱① 提交于 2019-12-25 18:54:43
问题 Here i have using swiftyJson pod library for response data. normal json response data i could able to get data but for complex i could not make it. here is my code to get data from response: private func makeHTTPGetRequest(path: String, onCompletion: @escaping ServiceResponse) { let user = "David****" let password = "**************" let loginString = "\(user):\(password)" guard let loginData = loginString.data(using: String.Encoding.utf8) else { return } let base64LoginString = loginData

Parsing the JSON data with Codable

对着背影说爱祢 提交于 2019-12-25 18:12:47
问题 I have a JSON response that I am parsing with the help of codable models. Even though my models look good, I am getting the below error, FAILURE: typeMismatch(Swift.Dictionary<Swift.String, Any>, Swift.DecodingError.Context(codingPath: [CodingKeys(stringValue: “data”, intValue: nil) The JSON response is: { "status": "success", "message": "successfully.", "user": { "username": "admin", "profileImage": "/storage/default.png" }, "data": { "cash": { "withdrawableCash": "$99999910",

Alamofire parameter only accepts [String : Anyobject]?

孤人 提交于 2019-12-25 13:16:48
问题 I'm using Alamofire which is an HTTP networking library in Swift, and am trying to make a PUT request with the json below as the parameter in the request, but it seems it doesn't like the versions field because it has another dictionary inside of it. Is there no way around this? var reqJson = [ "asdf": "sdfs", "lsd": "asdf", "asdf" : "coc", "qwer": "sdf", "cvc": "kljb", "xcv": "qwe", "versions": [ [ "version": "\(version)", "component": "\(compName)" ] ] ] Alamofire.request(.PUT, baseURL + "

Alamofire parameter only accepts [String : Anyobject]?

我是研究僧i 提交于 2019-12-25 13:16:09
问题 I'm using Alamofire which is an HTTP networking library in Swift, and am trying to make a PUT request with the json below as the parameter in the request, but it seems it doesn't like the versions field because it has another dictionary inside of it. Is there no way around this? var reqJson = [ "asdf": "sdfs", "lsd": "asdf", "asdf" : "coc", "qwer": "sdf", "cvc": "kljb", "xcv": "qwe", "versions": [ [ "version": "\(version)", "component": "\(compName)" ] ] ] Alamofire.request(.PUT, baseURL + "

How to use Alamofires ServerTrustPolicy.disableEvaluation in swift 3

我与影子孤独终老i 提交于 2019-12-25 10:52:13
问题 This is my session manager class import UIKit import Alamofire import ObjectMapper import AlamofireObjectMapper import Reqres class Manager: SessionManager { static let sharedInstance: Manager = Manager() static let manager: Manager = { let configuration = Reqres.defaultSessionConfiguration() let manager = Manager(configuration: configuration) return manager }() func getRequest(url:URL,param:Parameters,withSuccess success:@escaping (_ response: Dictionary<String, Any>) -> ()){ guard Utils

How to download image from JSON using the Swift 3 and Alamofire?

浪子不回头ぞ 提交于 2019-12-25 09:08:03
问题 How to download image from JSON using Alamofire and Swift 3? I am getting dictionary of data. See the following JSON response. I am able to print data in labels but I can't download the image. This is the response I am getting from the API. userJson userJson userJson userJson ["status": 1, "student": { "admission_date" = "14/06/2017"; "admission_no" = 13538; "class_teacher" = "Caroline Forbes"; dob = "04/05/2001"; email = "ranisagar.sivadas@gmail.com"; "father_name" = "SAGAR SIVADAS"; gender