I'm making web requests using AFNetworking. I subclassed NSURLProtocol and method swizzled it to override the default NSURLSessionConfiguration and add my protocol class to intercept web requests. When canInit is called I try to print the request data, specifically I want the body and query but it always prints null for both. I know the requests are being correctly intercepted they just don't have any body/query data. Does anyone know why this is? How do I go about getting the body data?
So after doing some research I found that the apple docs say this about a NSURLRequests body and bodystream:
The receiver will have either an HTTP body or an HTTP body stream, only one may be set for a request. A HTTP body stream is preserved when copying an NSURLRequest object, but is lost when a request is archived using the NSCoding protocol.
So, after checking the httpbodystream I found that was where the actual body was being stored. I had to copy the input stream, convert it to data, convert that to string and print. Here's a reference on how I did that:
How to convert NSInputStream to NSString or how to read NSInputStream