Using a proxy in UIWebView

1151 views
Skip to first unread message

Mehuge

unread,
Jul 25, 2011, 6:14:07 AM7/25/11
to ASIHTTPRequest
I know this is not directly related to ASIHTTPRequest but asking the
question here because this is where the http networking knowledge
hangs out :) and because ASIHTTPWebPageRequest I think is trying to
partly solve this problem and so has probably looked at and understood
the issues.

I have a UIWebView in my application, it implements some extensions,
installs its own JavaScript API into each web page which allows some
interaction between the page and the application, for instance,
popover menus when a user touches a point in the webview etc. This is
working fine so far.

The problem I have is that I need the web pages to be able to work
through a custom proxy server (though implementing a SOCKS proxy
server might be an option). The custom proxy server proxies requests
to one of many possible back-end systems based on previous
authentication (ie depending on login details, depends which back-end
system requests are proxied to).

The problem I have is when viewing a web page in UIWebView the initial
request can go through the proxy, as I build the URL, as can any
clicked links, because I can catch those and massage the URL, but
resources within the web page and AJAX requests will try and load
directly based on the base URL of the web page. There doesn't seem to
be any way to intercept these requests so I can send them through the
proxy.

ASIHTTPWebPageRequest appears to be trying to solve this issue by
downloading the content first, and dealing with referenced resources
and downloading those also, and the result can then be displayed in a
UIWebView. However, how are AJAX calls within the page going to be
dealt with? These will have the same issue as above.

Is there any way to (legally) intercept all requests (including those
made for resources such as images, scripts, css etc) made by UIWebView
and have ASIHTTPRequest deal with each request?

Can I set up an HTTP proxy for UIWebView, either for an instance of
UIWebView or at an application level?

Other options I have considered and have not ruled out are
to install some javascript code that will intercept all requests for
resources and update their URLs / scan for resources and edit their
urls
or
as I do have control of the web content that will be viewed via the
proxy, have the web content understand that it is being viewed in a
webview and co-operate by requesting its resources and firing its AJAX
requests via the proxy, though this latter option I would rather
avoid.
or
a combination of the two

Also someone mentioned to me perhaps using a PAC script would work.
How do I install a PAC script in a UIWebView - is that even possible?

Dan

unread,
Aug 22, 2013, 7:54:45 PM8/22/13
to asihttp...@googlegroups.com
PAC is not something you would run on the UIWebView
Reply all
Reply to author
Forward
0 new messages