title: Cancel a request Alamofire
body: <p>I am sending a request which is triggered based on timer. But if I press the back button the request still seems to be active and the response in turns crashes the app. Kindly suggest a way to cancel the request.</p>
  
  <p>Using Xcode 8.2.1
  Swift 3</p>
  
  <p>Here is the sample request :</p>
  
  <pre><code>Alamofire.request(path!, method: .post, parameters: parameters, encoding: JSONEncoding.default, headers: createHeader()).responseJSON {
      response in
      switch response.result {
      case .success(let data):
          success(data as AnyObject?)
      case .failure(let error) :
          failure(error as NSError)
      }
  }
  </code></pre>
  
  <p>Even tried invalidating the timer on viewDidDisappear but to no help.</p>
  
  <p>Thanks !!</p>