Built-in AFNetworking tools
For AFNetworking 1.x, use AFHTTPRequestOperationLogger
.
For AFNetworking 2.x, use AFNetworkActivityLogger
.
These tools both use the NSNotification
broadcast by AFNetworking to log request and response data to the console. The amount of information to be displayed is configurable, and they can be configured to ignore certain operations.
Examination in Xcode without these tools
HTTP Requests (outgoing data)
If you want to examine the body of an outgoing request, look at the NSURLRequest
's HTTPBody
parameter, which is a property on your AFHTTPRequestOperation
.
For example, in the method -[AFHTTPClient getPath:
parameters:
success:
failure:]
, after the request is made, you can type this into the debugger:
po [[NSString alloc] initWithData:request.HTTPBody encoding:4]
4 is NSUTF8StringEncoding
, as defined in NSString.h.
The NSURLRequest
's HTTPMethod
parameter provides the method (GET, POST, PUT, etc.) as an NSString
.
HTTP Responses (incoming data)
When your server responds, your success completion block is passed an AFHTTPRequestOperation
object (called operation
by default). You can:
p (int)[[operation response] statusCode]
to see the status code
po [[operation response] allHeaderFields]
to see the headers
po [operation responseString]
to see the response body
po [operation responseObject]
to see the response object (which may be nil
if it couldn't be serialized)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…