【发布时间】:2015-12-01 09:01:17
【问题描述】:
tl;博士; 我想使用 Swift 打印生成的(由Alamofire)请求(或至少是请求正文)
我收到NSMutableURLRequest 对象。
我试过了:
Alamofire.request(.POST, URL, parameters: params)
.responseJSON{ request, response, JSON, error in
println(request)
但我收到(调试器输出):
(lldb) p println(request)
<NSMutableURLRequest: 0x7faac257f520> { URL: http://apphb.com/api/x }
也许description?
(lldb) p println(request.description)
<NSMutableURLRequest: 0x7faac257f520> { URL: http://apphb.com/api/x}
HTTPBody? (... 下面 == 手动缩短输出是我)
(lldb) p println(request.HTTPBody!)
<416e7377 65727325 ... 38323833>
编码 - 没那么糟糕,但没有格式化
(lldb) p println(NSString(data: request.HTTPBody!, encoding:NSUTF8StringEncoding)!)
Answers%5B%5D%5BAnswerId%5D=65&An...
但我想以 JSON 格式获取完整的请求和正文(使用 SwiftyJSON?) - 如何实现?
【问题讨论】:
-
我不熟悉 Alamofire,但我敢打赌响应和 JSON 在
response和JSON变量中,而不是在request中。println(response)打印什么? -
最后一行错误 - 我需要请求(响应和响应 JSON 打印良好)
标签: swift alamofire swifty-json