alamofire

Set content-type when performing GET using Alamofire 4

半城伤御伤魂 提交于 2020-01-07 08:27:12
问题 All I want to do is make a simple GET request using Alamofire 4 but set the content-type to application/json I cannot see a way of doing it on the request. How do I do this. I thought this would work but it doesn't. Alamofire.request("https://dummy.com/dummy", method: .get, parameters: nil, encoding: JSONEncoding.default, headers: nil).responseJSON { response in print(response.request) // original URL request print(response.response) // HTTP URL response print(response.data) // server data

Authorization header using Alamofire

微笑、不失礼 提交于 2020-01-07 06:40:30
问题 I'm working with an API which puts an authorization key in the header, it works fine in Postman: And it's my code: let url = Requests.listCities(withLanguage: .en) let headers: HTTPHeaders = [ "Authorization": "pmJAdo5N26WW74kCEy6RRvIdCScFCbAtKc2o0FNy"] Alamofire.request(url, method: .get, parameters: nil, encoding: URLEncoding.default, headers: headers) .validate(contentType: [MIMEType.JSON]) .responseJSON {response in completion(response) } The response is: SUCCESS: { error = Unauthorized;

How to pass JSON data to another view controller from login function using post method?

余生颓废 提交于 2020-01-07 05:42:14
问题 I m having blank data in another view controller, I can pass data between table view controller but I m having a problem to parse data from login method and pass access token or username from JSON? @IBOutlet weak var username_textfield: UITextField! @IBOutlet weak var password_textfield: UITextField! var logindata : [Login] = [] var myResponse : JSON = nil func getlogin(){ let headers = [ "Content-Type": "application/x-www-form-urlencoded" ] let parameters = [ "UserName": username_textfield

How to pass JSON data to another view controller from login function using post method?

跟風遠走 提交于 2020-01-07 05:41:46
问题 I m having blank data in another view controller, I can pass data between table view controller but I m having a problem to parse data from login method and pass access token or username from JSON? @IBOutlet weak var username_textfield: UITextField! @IBOutlet weak var password_textfield: UITextField! var logindata : [Login] = [] var myResponse : JSON = nil func getlogin(){ let headers = [ "Content-Type": "application/x-www-form-urlencoded" ] let parameters = [ "UserName": username_textfield

Swift Alamofire 4 add header to request without custom request adapter

a 夏天 提交于 2020-01-07 03:10:26
问题 I am trying to migrate to the new alamofire, and in the docs it tells me i need to do a custom request adapter in order to add headers to requests, i think thats not confortable everywhere and i would like to just add the header in the request instead of having to make an adaper for certain requests, anyone have found a way to do it? below i shared my old code (commented) and my new code wich is missing a header parameter. Alamofire.request(url, method: .post , parameters: parameters,

SerializationFailure error while posting data with Alamofire

假如想象 提交于 2020-01-07 02:24:10
问题 I am trying to save some text data and an image to server using Alamofire but I am getting following error: FAILURE: responseSerializationFailed(Alamofire.AFError.ResponseSerializationFailureReason.jsonSerializationFailed(Error Domain=NSCocoaErrorDomain Code=3840 "Invalid value around character 0." UserInfo={NSDebugDescription=Invalid value around character 0.})) My Code: internal func postContent(forApi Name:String, image:UIImage?, withData payload:[String: String], success: ((_ response:

array return empty when trying to call from outside the function [swift] [duplicate]

為{幸葍}努か 提交于 2020-01-07 01:40:08
问题 This question already has answers here : How to return value from Alamofire (5 answers) Closed 3 years ago . I got this calling api function: func searchResults(){ let urlString = "http://dev.jocom.com.my/feed" Alamofire.request(.POST, urlString , parameters: ["req" : "pro_name", "code" : searchString!]) .responseData { response in switch response.result { case .Success: let apiSearchXML = SWXMLHash.parse(response.data!) for elem in apiSearchXML["rss"]["channel"]["item"]{ self.imageURL.append

Alamofire -安全认证

穿精又带淫゛_ 提交于 2020-01-07 01:38:54
基于Alamofire 5.0.0 分析网络的安全认证。同时介绍一些 HTTP 与 HTTPS 的一些相关知识 HTTP 特性 无连接:无连接的含义是限制每次连接只处理一个请求。服务器处理完客户的请求,并收到客户的应答后,即断开连接。采用这种方式可以节省传输时间。 无状态:HTTP协议是无状态协议。无状态是指协议对于事务处理没有记忆能力。缺少状态意味着如果后续处理需要前面的信息,则它必须重传,这样可能导致每次连接传送的数据量增大。另一方面,在服务器不需要先前信息时它的应答就较快。 简单快速:客户向服务器请求服务时,只需传送请求方法和路径。请求方法常用的有 GET、HEAD、POST。每种方法规定了客户与服务器联系的类型不同。由于HTTP协议简单,使得HTTP服务器的程序规模小,因而通信速度很快。 灵活:HTTP 允许传输任意类型的数据对象。正在传输的类型由Content-Type(Content-Type 是 HTTP包 中用来表示内容类型的标识)加以标记。 HTTP 存在的问题 1.安全性差 2.每次请求传输结束,重新请求又要建立连接 3.后续处理之前信息必须重传,损耗性能 加密算法 1.对成加密 在对称加密当中加密使用的秘钥和解密使用的秘钥是相同的。也就是加密和解密都是同一个秘钥。这样秘钥的安全性就非常重要,秘钥是一定不能公开的 存在的缺点:对称加密的缺点就在于如果秘钥要是泄露

Authenticated http request swift Alamofire

走远了吗. 提交于 2020-01-06 19:43:09
问题 I'm struggling with getting this to work to make request to my API. Without a token works, but when I try to add additional headers, things turn to be complicated, for me. First, the structure. one class called: APIAsyncTask that makes the requests one class called APIParams , just a data holder to send parameters to the APIAsyncTask class. one class called DatabaseAPI that makes that builds the parameters, and send that to the APIAsyncTask class. DatabaseAPI func someMethod() { let task =

JSON could not be serialized because of error:

纵饮孤独 提交于 2020-01-06 07:59:06
问题 I am using Alamofire 4.0, While making network call I am getting below error during the app review so that my app is getting rejected. But for me and my client it's working fine we are never getting below error JSON could not be serialized because of error: The data couldn’t be read because it isn’t in the correct format. We also checked that the service call is not hitting the server(so not getting any help from their side), Please find the code snippet manager.request(requestURL, method