I'm trying to send a simple request with established VPN connection (NEPacketTunnelProvider
) and I try to use URLSession.shared which sends traffic outside of the tunnel. But that resource is only available inside the tunnel.
Is there a possible way how to send it via VPN?
P.S. I use WireGuard sdk to establish vpn connection, I as I can see there isn't any api to make such a request.
Here is a request that I sent,instead of ifconfig.co
I use real domain which is accessible inside the tunnel
let request = URLRequest(url: .init(string: "https://ifconfig.co/json")!)
URLSession.shared.dataTask(with: request) { data, response, error in
log("Requestion Status FINISHED")
if let data = data {
let dataString = String(data: data, encoding: .utf8)
log("DataString - \(dataString ?? "NULL")")
}
if let httpResponse = response as? HTTPURLResponse {
log("httpResponse status code - \(httpResponse.statusCode)")
}
if let error = error {
log("Error - \(error.localizedDescription)")
}
}
.resume()