3

I want to know if it is possible to tunnel web requests, and of course what to use/implement.

I have already written subclasses of NSInputStream and NSOutputStream to send & receive data via my custom proxy server, which is working wonderfully for socket connections.

I have tried to implement the delegates of UIWebView and NSURLRequest, but I was unable to capture all the HTTP requests made from the UIWebView.

Thank you in advance.

Pada
  • 646
  • 5
  • 13
  • We'll need more details on what it is you're trying to achieve. Is there a reason the system-wide HTTP(S) / SOCKS proxy support does not provide what you want? – Aidan Steele Mar 16 '11 at 08:37
  • I'm using a custom proxy server that uses RSA encryption for key exchange and then AES encryption for transmitting the data, so a SOCKS proxy is out of the question for me. I'm actually just trying to port Java code to the iPhone, but now I'm stuck on tunneling of the HTTP related connections. – Pada Mar 18 '11 at 08:13

1 Answers1

0

You could try using category to catch all the relevant method calls (template below). However beware dragons and make sure that you consider using the system proxy route before doing this.

UIWebView+PrivateProxy.h

@interface UIWebView (PrivateProxy) 
       - (void)loadRequest:(NSURLRequest *)request;

@end

UIWebView+PrivateProxy.m

@implementation UIWebView (PrivateProxy) 
   - (void)loadRequest:(NSURLRequest *)request {
       if(request.something ....) {
          // handle yourself ...
       } else { 
          [super loadRequest:request]; // use stanadrd implementation
       }
   }
@end

Off course you'll probably have to override more methods e.g. reload, stopLoading, etc.

Maria Zverina
  • 10,863
  • 3
  • 44
  • 61
  • Thanks Maria. I have left a comment on my first post on why I don't want to use a standard SOCKS proxy. I have already tried to create a subclass of UIWebView and I did implement the loadRequest method, which was triggered ONLY ONCE. I'm not sure if I should try and use method Swizzling, because you can't call [super loadRequest:request] with a categorized UIWebView class, since UIView is it's parent and it doesn't have the loadRequest function. Do you reckon that the use of method Swizzling might fix my problem of loadRequest being called once - even for www.google.com, which has images – Pada Mar 18 '11 at 08:24
  • Please note that my answer does NOT subclass UIWebView. It uses categories to extend existing class behaviour - hence it has system wide effect. For more on categories please see http://macdevelopertips.com/objective-c/objective-c-categories.html – Maria Zverina Mar 18 '11 at 14:44
  • 1
    Aaah .. the penny just dropped. I think I finally understood the question. Would this work for you? http://www.icab.de/blog/2009/08/18/url-filtering-with-uiwebview-on-the-iphone/ – Maria Zverina Mar 18 '11 at 14:48