Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generate cURL output from Alamofire request?

Tags:

curl

alamofire

The documentation for Alamofire says that it produces cURL debug output. But for the life of me, I can't figure out how to retrieve the cURL for my request. Can someone enlighten me on the proper syntax for showing the cURL request as in my debug console?

Assuming I have a simple request of the form

Alamofire.request(.POST, servicePath, parameters: requestParams, encoding: .JSON)

Where can I inject a print() to see the generated request?

like image 209
Greg Ferreri Avatar asked Dec 03 '15 13:12

Greg Ferreri


3 Answers

I just did this and it works:

let someRequest = Alamofire.request(.POST, servicePath, parameters: requestParams, encoding: .JSON)
debugPrint(someRequest)
like image 128
karlingen Avatar answered Oct 11 '22 06:10

karlingen


Here's an updated answer for Swift 5 and AlamoFire 5

let headers: HTTPHeaders = [
    "Accept": "application/json"
]

AF.request(myURL, method: .get, headers: headers).validate().responseJSON { response in
    switch response.result {
        case .success(let value):
            print(value)
        case .failure(let error):
            print("oops")
            print(error)
        }
}.cURLDescription { description in
    print(description)
}
like image 34
tww0003 Avatar answered Oct 11 '22 05:10

tww0003


try this

let task = AF.request(url)
task.responseData { response in
   print(task.debugDescription)
}

from here

like image 44
Fitsyu Avatar answered Oct 11 '22 06:10

Fitsyu