Hi Forum
I have several "function(s)" like this code below that open different environments.but I would like to separate the following line into 2 variables, as here below.
let url = URL(string: "http...://192.168.0.196:8000/xmlcommand")!
ServIP = 192.168.0.196
Port = 8000
So that the ServIP can be put into a "user" typed input Configuration field in my App so user can add different IP's for different systems this input field is asks users to enter the ServIP, and Port in this format "192.168.0.196:8000 so these can be reused in these functions, instead of hardcoded IP's.
New string in the code should then look like this:
let url = URL(string: "http...://ServIP:Port/xmlcommand")!
I have been trying to split these up in some let lines but can't get it right. anyone can tell me how to split these into variables?
Br
Enevold
I have several "function(s)" like this code below that open different environments.but I would like to separate the following line into 2 variables, as here below.
let url = URL(string: "http...://192.168.0.196:8000/xmlcommand")!
ServIP = 192.168.0.196
Port = 8000
So that the ServIP can be put into a "user" typed input Configuration field in my App so user can add different IP's for different systems this input field is asks users to enter the ServIP, and Port in this format "192.168.0.196:8000 so these can be reused in these functions, instead of hardcoded IP's.
New string in the code should then look like this:
let url = URL(string: "http...://ServIP:Port/xmlcommand")!
I have been trying to split these up in some let lines but can't get it right. anyone can tell me how to split these into variables?
Code Block // Open Environment called "Environment_Name" func sendHttpPostAnimals() { let session = URLSession(configuration: .default) let url = URL(string: "http://192.168.0.196:8000/xmlcommand")! var request = URLRequest(url: url) request.httpMethod = "POST" request.setValue("text/plain", forHTTPHeaderField: "Content-Type") // I guess this can be "text/xml" // Working line request.httpBody = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><Commands><command type=\"open\"><name>environments/Animals.hwe</name><id>a1</id></command></Commands>".data(using: .utf8) let task = session.dataTask(with: request) { data, response, error in // print(data as Any) // print(response as Any) // print(error as Any) // do something with the result print(data as Any? as Any) if let data = data { print(String(data: data, encoding: .utf8)!) } else { print("no data") } } task.resume() // <- otherwise your network request won't be started
Br
Enevold