I have just started using iOS technologies, and developing an iPhone application using Swift.
I am trying to query server using following code:
var url = NSURL(string: "http://someurl:8080/?type=Refresh")
var request = NSURLRequest(URL: url!)
var connection = NSURLConnection(request: request, delegate: self, startImmediately: true)
But I need to setup proxy on my iPhone device if I need to query that server. So now I want to setup http proxy (server and port) in Swift code itself.
I looked into CFProxySupport Reference by Apple, but not understanding how can I use it. I have written following code till now:
var proxy_server: CFString = “proxy” // proxy server
var proxy_port: CFNumber = 8080 // port
var keys: [CFStringRef] = [kCFProxyTypeKey, kCFProxyHostNameKey, kCFProxyPortNumberKey]
var values: [CFTypeRef] = [kCFProxyTypeHTTP, proxy_server, proxy_port]
var proxy_dict: CFDictionary = CFDictionaryCreate(
kCFAllocatorDefault,
UnsafeMutablePointer<UnsafePointer<Void>>(keys),
UnsafeMutablePointer<UnsafePointer<Void>>(values),
3,
nil,
nil)
var proxies: Unmanaged<CFArray> = CFNetworkCopyProxiesForURL(NSURL(string: "http://someurl:8080"), proxy_dict)
Can anyone please tell me how to use proxies
to setup proxy?
Thanks!