<
import SwiftUI
struct ContentView: View {
@State var username: String = "."
@State var password: String = "."
var body: some View {
ZStack {
VStack {
.onAppear(perform: {
if 1==1 {
let myUrl = URL(string: ".");
var request = URLRequest(url:myUrl!)
request.httpMethod = "POST"// Compose a query string
let postString = "Name=\($username)&Passwort=\($password)";
request.httpBody = postString.data(using: String.Encoding.utf8);
let task = URLSession.shared.dataTask(with: request) { (data: Data?, response: URLResponse?, error: Error?) in
if error != nil
{
print("error=\(error)")
return
}
// You can print out response object
print("response = \(response)")
//Let's convert response sent from a server side script to a NSDictionary object:
do {
let json = try JSONSerialization.jsonObject(with: data!, options: .mutableContainers) as? NSDictionary
if let parseJSON = json {
// Now we can access value of First Name by its key
let firstNameValue = parseJSON["Name"] as? String
print("firstNameValue: \(firstNameValue)")
let dateien = firstNameValue?.components(separatedBy: ",")
print(dateien)
}
} catch {
print(error)
}
}
task.resume()
}
}
)
}
}
}
}
struct TestView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
} >
Topic:
UI Frameworks
SubTopic:
SwiftUI
Tags: