Search
 
SCRIPT & CODE EXAMPLE
 

SWIFT

swift post request

 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 :: get keyboard height swift 
Swift :: how to bold text swiftui 
Swift :: IOS create UIAlertViewController programmatically 
Swift :: create dictionary swift 
Swift :: swift scroll to tableviewcell 
Swift :: how to loop swift 
Swift :: swift get device screen size 
Swift :: make preivew in dark mode swiftui 
Swift :: define struct swift 
Swift :: go to view controller programmatically swift 
Swift :: create class swift 
Swift :: hide scroll view indicators bar swiftui 
Swift :: swift uitextfield placeholder color 
Swift :: swift5 get uiview height 
Swift :: ios get device id 
Swift :: swiftlint 
Swift :: swift remove all pins from mapkit 
Swift :: setting a local notification at specific time every day swift 
Swift :: Swift Closure Parameters 
Swift :: toggle button swift 
Swift :: two value sum 
Swift :: Swift Use of Hash Function 
Swift :: ring Desktop, WebAssembly and Mobile Using QTableWidget 
Swift :: Save and Load Data From Keychain ios swift 
Swift :: Swift Nested Ternary Operators 
Swift :: UISearchController keys 
Swift :: crud php native with navicat 
Swift :: swift ease in out animatekeyframes 
Swift :: ln -s ~/.platformio/penv/bin/platformio /usr/local/bin/platformio ln -s ~/.platformio/penv/bin/pio /usr/local/bin/pio ln -s ~/.platformio/penv/bin/piodebuggdb /usr/local/bin/piodebuggdb 
Swift :: How to make dart typing stricter 
ADD CONTENT
Topic
Content
Source link
Name
4+3 =