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?
I just did this and it works:
let someRequest = Alamofire.request(.POST, servicePath, parameters: requestParams, encoding: .JSON)
debugPrint(someRequest)
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)
}
try this
let task = AF.request(url)
task.responseData { response in
print(task.debugDescription)
}
from here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With