alamofire

Prevent redirect response with Alamofire in Swift

↘锁芯ラ 提交于 2019-12-03 21:48:19
I'm looking for example code how to prevent redirect response (status code 3xx) when request web api. I'm using Swift with Alamofire 1.2. I have tried: delegate.taskWillPerformHTTPRedirection = { (session: NSURLSession!, task: NSURLSessionTask!, response: NSHTTPURLResponse!, request: NSURLRequest!) in return nil } but not work I've also tried: https://github.com/Alamofire/Alamofire/pull/350/files and have changed my own code to: var acc = self.txtAccount.text var pwd = self.txtPassword.text var url : String = "http://10.1.0.2:8081/wordpress/wp-json/users/me" let delegate = Alamofire.Manager

How can we upload multipart form data with nested JSON parameters in Swift?

一世执手 提交于 2019-12-03 21:33:59
I need to upload an image to the server endpoint where the structure has to be as following: { "image": { "file": imageData }, "access_token": access_token } How can I send such a request using NSURLSession (or maybe even Alamofire or AFNetworking)? Rob You cannot just include binary image data in a JSON request. JSON requires text representation, so if you do this, you must convert it to string (e.g. base64 encoding), use that in the JSON, and then the server code would presumably convert the base64 string back to binary data before attempting to use it. But if you were base64 encoding of the

Alamofire Image: Fetch Image from AutoPurgingImageCache after af_setImageWithURL()

℡╲_俬逩灬. 提交于 2019-12-03 20:52:57
I use AlamofireImage in my project. I use someImageView.af_setImageWithURL(url) a lot. However at some point I need to fetch an image manually from the imageCache, because I do not want to apply it to an UIImageView. This brings up 2 problems: I can access the image cache directly by creating one with let imageCache = AutoPurgingImageCache() . Is this the same cache as .af_setImageWithURL() uses (Singleton)? Or is this a new one? Which is worthless in my case, because I could not profit from the prefilled cache. Given this is the same cache: How can I fetch the correct image? I thought about

cURL with Alamofire - Swift - multipart/form-data

感情迁移 提交于 2019-12-03 17:25:57
First, im sorry if this question is stupid but im pretty new to this stuff. I've tried different things to create the swift equivalent of this cURL request with Alamofire, but I don't know how to send the image as a multipart/form-data to the API. curl -X POST -F "file=@/Users/nicolas/sample.png" -F "mode=document_photo" https://api.idolondemand.com/1/api/sync/ocrdocument/v1 -F "apikey=xxx-xxx-xxx-xxx-xxx" I think current code is pretty wrong for this type of request, but still i'm gonna post it for you: func getOCR(image: UIImage) { let url = "https://api.idolondemand.com/1/api/sync

How to use a Proxy Server with Alamofire 4 and Swift 3

随声附和 提交于 2019-12-03 16:14:36
问题 Please don't mark as duplicate, I haven't been able to solve my Issue with the existing threads. I'm trying to use my Proxy for an API request that needs a specified IP. To debug my issue, I'm requesting the IP from a webservice. This is my current code: import UIKit import Alamofire class ViewController: UIViewController { var requestManager = Alamofire.SessionManager.default override func viewDidLoad() { super.viewDidLoad() } override func viewDidAppear(_ animated: Bool) { super

How to send total model object as a parameter of Alamofire post method in Swift3?

99封情书 提交于 2019-12-03 14:36:25
I have a model class like this class Example() { var name:String? var age:String? var marks:String? } I'm adding data to that model class let example = Example() example.name = "ABC" example.age = "10" example.marks = "10" After that I converted to JSON then I posted Alamofire.request(URL, method:.post, parameters: example) Alamofire not accepting parameters only its accepting like parameters = ["":"","",""]-->key value based , so I tried to convert model to JSON, JSON to dictionary, even though not accepting its showing like parameters problem. Exactly I need total model object need to send

Proper model for multiple Alamofire requests for multiple websites

我只是一个虾纸丫 提交于 2019-12-03 14:15:10
问题 I am using Alamofire to scrap web pages for some data, let’s say News. News is a generic object with something like title, content, picture, date, author etc. However for each web site, I use different method. For some I use json for others I use hpple to extract the data. How can I create a some kind of service for each website. Should I create different Services for each web site or is there a better way to use some kind of generic function templates for each web site. Like Login() Fetch()

Alamofire Post Request Issues

我怕爱的太早我们不能终老 提交于 2019-12-03 14:02:23
问题 let parameters = [ "checkout": [ "email": "john.smith@example.com", "line_items": [ "variant_id": 31342168513, "quantity": 1 ], "shipping_address": [ "first_name": "John", "last_name": "Smith", "address1": "126 York St.", "city": "Ottawa", "province_code": "ON", "country_code": "CA", "phone": "(123)456-7890", "zip": "K1N 5T5" ] ] ] let urlString = "https://\(Key):\(Password)@sapphireonline-staging.myshopify.com/admin/checkouts.json" let headers: HTTPHeaders = [ "X-Shopify-Storefront-Access

Upload image with alamofire

只愿长相守 提交于 2019-12-03 13:46:47
I'm trying to upload an image to server with Alamofire but my code doesn't work. This is my code: var parameters = ["image": "1.jpg"] let image = UIImage(named: "1.jpg") let imageData = UIImagePNGRepresentation(image) let urlRequest = urlRequestWithComponents("http://tranthanhphongcntt.esy.es/task_manager/IOSFileUpload/", parameters: parameters, imageData: imageData) Alamofire.upload(urlRequest.0, data: urlRequest.1) .progress { (bytesWritten, totalBytesWritten, totalBytesExpectedToWrite) in println("\(totalBytesWritten) / \(totalBytesExpectedToWrite)") } .responseJSON { (request, response,

Multipart-form (image,parameters,headers) Post request with Alamofire in swift

99封情书 提交于 2019-12-03 12:54:01
Firstly, i want to say i am new to swift, and know a little.So any help would be appriciated. I have a multipart-data form which has a image (profile-image), a few parameters (first-name, last-name) and headers(userid, hashCode). I want to send a POST request to submit the form. I have been able to make POST request with only, headers and other parameters except image as: let headers = [ "user_id": (Helper.getUserInfo()?.user_id)!, "hash_code":(Helper.getUserInfo()?.hash_code)!, ] let params = [ "name": self.name.text!, "address":self.address.text!] Alamofire.request(.POST, kFormUrl,