I just started using iOS technology and developed an iPhone app using Swift.
I am trying to request a server using the 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 configure a proxy server on my iPhone device if I need to request this server. So now I want to configure the HTTP proxy (server and port) in the Swift code itself.
I reviewed the Apple CFProxySupport Handbook , but did not understand how I can use it. I have written the following code so far:
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 tell me how to use proxies to install a proxy server?
Thanks!
source share