Search code examples
iosobjective-cproxymknetworkkit

How to use MKNetwork framework for http proxy server in objective-C


I want to use a proxy server when opening a url connection with objective-c.But I don't want to use any frameworks other than MKNetworkKit(a third party framework) in my project.Can anyone tell me how to accomplish this?


Solution

  • MKNetworkKit has no special support for HTTP proxies, but, because it uses NSURLConnection and NSURLRequest, you can add proxy support as described in this answer: How to add a proxy to NSURLRequest.

    In short:

    1. Implement a custom NSURLProtocol that adds your proxy information to the request
    2. Register your protocol with the URL loading system (+[NSURLProtocol registerClass:])
    3. Use MKNetworkKit as you normally would to load URLs with your custom protocol

    Of course, it might be simpler just to use CFNetwork directly.