1

I have search a lot but couldn't fine appropriate answer. there is a latest version of Alamofire 3.0 released . I would like to know how could i set a client side time out request . I have tried this on swift 3.0 ,Alamofire 3.0 version but its not work. var alamoFireManager : Alamofire.Manager?

let configuration = NSURLSessionConfiguration.defaultSessionConfiguration()
configuration.timeoutIntervalForRequest = 4 // seconds
configuration.timeoutIntervalForResource = 4
self.alamoFireManager = Alamofire.Manager(configuration: configuration)

self.alamoFireManager!.request(.POST, "http://oznet.go.ro/iDorMobile/ConfigServer/api.php/timeout/2", parameters: nil).responseJSON {
    (req, res, json, error)  in
    println("First json \(json)")
    println("First error \(error)")
}

Please help me Thanks in Advance

Peppo
  • 1,107
  • 1
  • 12
  • 19
  • its not about alamofire but you can check this link http://stackoverflow.com/questions/8304560/how-to-set-a-timeout-with-afnetworking – Talha Q Oct 19 '15 at 20:39

1 Answers1

1

You can set the timeout in the header of http request, like the below example.

let request = NSMutableURLRequest(URL: NSURL.init(string: "URL")!)
request.HTTPMethod = "POST"
request.setValue("application/json", forHTTPHeaderField: "Content-Type")
request.timeoutInterval = 10 // 10 secs
let values = ["key": "value"]
request.HTTPBody = try! NSJSONSerialization.dataWithJSONObject(values, options: [])
Alamofire.request(request).responseJSON {
            response in
    // do whatever you want here
}
BobGao
  • 770
  • 8
  • 18