“SWIFT URL -Anfrage” Code-Antworten

SWIFT URL -Anfrage

import Foundation

let apiUrl = URL(string: "https://api.chucknorris.io/jokes/random")!
let dataTask = URLSession.shared.dataTask(with: apiUrl) { (data, response, error) in
    guard let data = data, error == nil else {
        print("no data")
    }
    let jsonResult = try! JSONSerialization.jsonObject(with: data, options: []) as! [String: Any]
    print(jsonResult["value"])
}
dataTask.resume()
Adventurous Anteater

iOS stellen eine HTTP -Anfrage ab

let Url = String(format: "http://10.10.10.53:8080/sahambl/rest/sahamblsrv/userlogin")
    guard let serviceUrl = URL(string: Url) else { return }
    let parameters: [String: Any] = [
        "request": [
                "xusercode" : "YOUR USERCODE HERE",
                "xpassword": "YOUR PASSWORD HERE"
        ]
    ]
    var request = URLRequest(url: serviceUrl)
    request.httpMethod = "POST"
    request.setValue("Application/json", forHTTPHeaderField: "Content-Type")
    guard let httpBody = try? JSONSerialization.data(withJSONObject: parameters, options: []) else {
        return
    }
    request.httpBody = httpBody
    request.timeoutInterval = 20
    let session = URLSession.shared
    session.dataTask(with: request) { (data, response, error) in
        if let response = response {
            print(response)
        }
        if let data = data {
            do {
                let json = try JSONSerialization.jsonObject(with: data, options: [])
                print(json)
            } catch {
                print(error)
            }
        }
    }.resume()
}
Gleaming Gazelle

Ähnliche Antworten wie “SWIFT URL -Anfrage”

Fragen ähnlich wie “SWIFT URL -Anfrage”

Weitere verwandte Antworten zu “SWIFT URL -Anfrage” auf Swift

Durchsuchen Sie beliebte Code-Antworten nach Sprache

Durchsuchen Sie andere Codesprachen