Search
 
SCRIPT & CODE EXAMPLE
 

SWIFT

get request swift

let url = URL(string: "http://www.example.com")!

let task = URLSession.shared.dataTask(with: url) {(data, response, error) in
    guard let data = data else { return }
    print(String(data: data, encoding: .utf8)!)
}

task.resume()
Comment

swift http 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

get request swift

let url = URL(string: "http://www.example.com")!

let task = URLSession.shared.dataTask(with: url) {(data, response, error) in
    guard let data = data else { return }
    print(String(data: data, encoding: .utf8)!)
}

task.resume()
Comment

swift http 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 :: textfield style swiftui own 
Swift :: swift uipickerview 
Swift :: how to find uibutton title text 
Swift :: swift check dictionary has key 
Swift :: swiftui pintch to zoom 
Swift :: switches xcode 
Swift :: how to get the last element of an array in swift 
Swift :: how to add button dynamically in swift 4 
Swift :: swiftui scrollview hide scrollbar 
Swift :: swift remove all duplicates from an array 
Swift :: foreach swiftui object 
Swift :: append new element to dictionary in swift 
Swift :: random number swift 
Swift :: swift enum 
Swift :: how to style textfield swiftui 
Swift :: swift navigation bar title color 
Swift :: power swift 
Swift :: change individual element alignment swiftui 
Swift :: swift close view 
Swift :: average in array swift 
Swift :: convert uiimage to swiftui image 
Swift :: Swift Closures as Function Parameter 
Swift :: swift replace newlines with space 
Swift :: swift dictionary 
Swift :: Swift Half-Open Range 
Swift :: Swift enums with rawValue 
Swift :: Logical Operators Swift 
Swift :: store multiple items in one core data record 
Swift :: appendBytes: Lengt: SWIFT 
Swift :: crud php native with navicat 
ADD CONTENT
Topic
Content
Source link
Name
2+2 =