Created
June 26, 2018 02:49
-
-
Save MihaelIsaev/83866f306be7ebbc8201b12e1b452029 to your computer and use it in GitHub Desktop.
Example of http request through proxy for Vapor 3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public func boot(_ app: Application) throws { | |
let config = URLSessionConfiguration.default | |
config.requestCachePolicy = URLRequest.CachePolicy.reloadIgnoringLocalCacheData | |
config.connectionProxyDictionary = [AnyHashable: Any]() | |
config.connectionProxyDictionary?[kCFNetworkProxiesHTTPEnable as String] = 1 | |
config.connectionProxyDictionary?[kCFNetworkProxiesHTTPProxy as String] = "proxy-server.com" | |
config.connectionProxyDictionary?[kCFNetworkProxiesHTTPPort as String] = 8080 | |
let session = URLSession.init(configuration: config) | |
let client = FoundationClient(session, on: app) | |
let httpReq: HTTPRequest = HTTPRequest(method: HTTPMethod.GET, url: "http://destinationsite.com") | |
let req = Request(http: httpReq, using: app) | |
_ = client.send(req).map { res in | |
debugPrint(res) | |
}.catchMap { err in | |
debugPrint(err) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment