我在使用AFMotion SessionClient拦截SessionClient帖子请求时遇到问题。奇怪的是,我的代码在使用通用AFMotion :: HTTP.post动作
时工作正常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
这是我正在做的事情。发送到initWithRequest的请求参数似乎无法访问post数据,当使用SessionClient时,它确实可以正常工作并且在使用通用AFMotion :: HTTP.post时可以访问期望的参数