I'm having trouble intercepting SessionClient post requests using AFMotion SessionClient. Weirdly, my code works fine when using a generic AFMotion::HTTP.post action
class Protocol < NSURLProtocol
def self.canInitWithRequest(request)
return true
end
def initWithRequest(request, cachedResponse:response, client: client)
puts request.HTTPBody
end
end
NSURLProtocol.registerClass(Protocol)
# this works fine for intercepting data
AFMotion::HTTP.post("http://espn.com", {:msg => "I like sports"}) do
# the above will output msg="I like sports as expected"
end
# this doesn't work as expected
c = AFMotion::SessionClient.build "http://www.espn.com"
c.post("/", {:msg => "I like sports"} do
# the initWithRequest request object has nil for both the HTTPBodyStream and HTTPBody methods
end
Here's what I'm working on. The request parameter that is sent to initWithRequest doesn't seem to have access to the post data, when using a SessionClient, it does, however work fine and have access to the expected parameters when using a generic AFMotion::HTTP.post