larud
larud

Reputation: 13

SwiftUI: URL Request over specific browser

I want to retrieve a json from an intranet from outside the intranet in an iPad app. I have a VPN connection configured for this, but it only runs through the VMWare web browser. Safari uses the normal connection.

Is it possible, similar to the browser schemas, to use awbs:// instead of https:// and trigger the VPN configuration from an app? I don't want to open the browser though, I just want to use it. ;)

func getData() async {

    @State var value: [responsejson]?
    guard let url = URL(string: "https:/...") else {
                print("Invalid URL")
                return
            }
    let request = URLRequest(url: url)

            URLSession.shared.dataTask(with: request) {data, response, error in
                if let data = data {
                    if let decodedResponse = try? JSONDecoder().decode(responsejson.self, from: data) {
                        DispatchQueue.main.async {
                            self.response = decodedResponse.text
                        }
                        return
                    }
                }
                print("Error: \(error?.localizedDescription ?? "Unknown error")")

            }.resume()
}

I tried to replace here https with awbs, but unfortunately it did not work

Task <1039D056-FDC4-46EE-9635-373AF8723409>.<1> finished with error [-1002] Error Domain=NSURLErrorDomain Code=-1002 "unsupported URL" UserInfo={NSLocalizedDescription=unsupported URL, NSErrorFailingURLStringKey=awbs://(...)

Upvotes: 1

Views: 118

Answers (1)

Oleg
Oleg

Reputation: 791

http,https or awbs is not just a text, but a definition of the protocol. Protocol defines how the data will be transferred, and there is a specific list of protocol that iOS support. see https://en.wikipedia.org/wiki/Internet_protocol_suite (don't be confused with app-scheme, when you open a link and specific app response to it, these are two different things).

So when you try to create an instance of a URL object it actually parses a protocol and uses instructions to make a Request.

Upvotes: 0

Related Questions