I was hoping to capture AJAX post requests, and I have read this thread:
UIWebViewDelegate not monitoring XMLHttpRequest?>
However I was hoping there were some way to achieve this using Obj c without going through javascript. I already have a UIWebView setup along with its delegates. But since that doesn’t capture XMLHttpRequest, what should I implement to achieve this and where? Thank you.
Take a look at NSURLProtocol – this should enable you to intercept the requests.
Basically you would
– create your own class derived from NSURLProtocol and register it in applicationDidFinishLaunchingWithOptions: using NSURLProtocol:registerclass:
the connection will call initWithRequest:cachedResponse:client: and then startLoading.
you would call the connection back with URLProtocol:didReceiveResponse:cacheStoragePolicy:, some number of calls to URLProtocol:didLoadData:, and finally URLProtocolDidFinishLoading:
Once you have intercepted the calls you can allow them to procede, evesdrop on them, stop them from going forward, etc.