Search
 
SCRIPT & CODE EXAMPLE
 

SWIFT

post request in swift

 let url = URL(string: <#T##URL String#>)
        guard let requestUrl = url else { fatalError() }
        var request = URLRequest(url: requestUrl)
        request.httpMethod = "POST"
        // Set Request Header
        request.setValue("application/json", forHTTPHeaderField: "Accept")
        request.setValue("application/json", forHTTPHeaderField: "Content-Type")
        
        // Set HTTP Body
        let newTodoItem = RequestModel(id: 300, task: "")
        let jsonData = try JSONEncoder().encode(newTodoItem)
        request.httpBody = jsonData
        // Make Request
            let task = URLSession.shared.dataTask(with: request) { (data, response, error) in
                
                if let error = error {
                    print("Error took place (error)")
                    return
                }
                guard let data = data else {return}
                
         
        }
        task.resume()
Comment

PREVIOUS NEXT
Code Example
Swift :: costume font size swift ui 
Swift :: how do change title color in navigation bar 
Swift :: swift qrcode scanner 
Swift :: How to set back button text in Swift 
Swift :: disable swipe to delete swift 
Swift :: Thread 1: breakpoint 1.1 
Swift :: sort array alphabetically swift 4 
Swift :: porsche 
Swift :: define enum swift 
Swift :: swiftui 100 days 
Swift :: view controller modal fullscreen programmatically swift 5 
Swift :: check if string in array of string swift 
Swift :: how to covert a string into a float in swift 
Swift :: swft image 
Swift :: swift file size from url 
Swift :: swift add two arrays 
Swift :: remove and element from array firebase swift 5 
Swift :: how to set return type swift 
Swift :: uitextfield set max length 
Swift :: adding label to navigation bar 
Swift :: two variable sum in swift 
Swift :: Swift Omit Argument Labels 
Swift :: swift 5 flatMap wtih keypath 
Swift :: swiftui rectangle top corners radius 
Swift :: Swift Access Class Property using Objects 
Swift :: swift memberwise initializer 
Swift :: helen joseph 
Swift :: swift how to append an element 
Swift :: Javascript Define Swift Class 
Swift :: Swift Bitwise OR Operator 
ADD CONTENT
Topic
Content
Source link
Name
8+7 =