Anuj Arora
Anuj Arora

Reputation: 3047

Alamofire POST Returning Data

I am using Alamofire to make a post request to server. The post request is working fine.

Issue: When the post request is made, it returns some data which I need. How can I store/ retrieve that data

The POST Request:

Alamofire.request(.POST, postURL, parameters: params)

Upvotes: 1

Views: 671

Answers (2)

Talha Q
Talha Q

Reputation: 4360

If you are using the latest version of AlamoFire. If you are using the latest version of AlamoFire. Try this working fine for me.(Change request arguments based on your need)

let url1 = "http://yoururl.com"
let head = [ "Accept": "application/json;charset=UTF-8",
            "Content-Type": "application/json;charset=UTF-8"] // Adding headers
        let p = ["Email":"anything","Password": "123"] // Adding parameters if any

Alamofire.request(.POST,url1, parameters: p, encoding : .JSON, headers : head)
      .responseJSON { response in
             print(response.request)  // original URL request
             print(response.response) // URL response
             print(response.data)     // server data
             print(response.result)   // result of response serialization

  }

Upvotes: 0

Karson
Karson

Reputation: 216

to get the response closure add .response { request, response, data, error in } to the end of your code

ie

Alamofire.request(.POST, "http://httpbin.org/get", parameters: ["foo": "bar"])
     .response { request, response, data, error in
         print(request)
         print(response)
         print(data)
         print(error)
      }

Upvotes: 2

Related Questions