The easiest way I know is to wire up a UIWebView delegate and listen to all requests before they go through, and redirect the ones you care about through ASIHttpRequest and your custom proxy settings.
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
// Configure a proxy server manually
NSURL *url = [NSURL URLWithString:@"http://allseeing-i.com/ignore"];
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
[request setProxyHost:@"192.168.0.1"];
[request setProxyPort:3128];
// Alternatively, you can use a manually-specified Proxy Auto Config file (PAC)
// (It's probably best if you use a local file)
[request setPACurl:[NSURL URLWithString:@"file:///Users/ben/Desktop/test.pac"]];
// fire the request async
[request setDelegate:self];
[request startAsynchronous];
return NO;
}
- (void)requestFinished:(ASIHTTPRequest *)request
{
NSData *responseData = [request responseData];
// todo: save data to disk and load with [self webView]
}
It's a bit wonky,but it should work. Just remember to manage your memory properly and don't use this leaky example code... YMMV, I haven't even tested if this compiles, typed it all in the browser window with some copy and paste hackery.