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

PREVIOUS NEXT
Code Example
Swift :: swift get a rectangle centered 
Swift :: detect end of scroll in UICollectionView ios swift 
Swift :: swift uiswitch change size 
Swift :: pop the view controller xcode 
Swift :: uipageviewcontroller next button swift 
Swift :: loop key value swift 
Swift :: swift swipe gesture 
Swift :: swift push view controller 
Swift :: swift go back to previous view controller 
Swift :: generate random bool swift 
Swift :: how can i play video with url in a view in swift 
Swift :: power number in swift 
Swift :: swift round double to 2 decimal places 
Swift :: how to loop swift 
Swift :: swift url request 
Swift :: navigationbar large title swift 
Swift :: Swift Basic Input 
Swift :: swift dictionary contains key 
Swift :: swift 5 make image fit uiimageview 
Swift :: swift multiline string 
Swift :: uilabel set fon siz 
Swift :: how to recieve hex value from NSData swift 
Swift :: Swift Closure Parameters 
Swift :: uikit call swiftui view 
Swift :: how to present a uiview after an array of cards is empty swift 
Swift :: Swift Floating-point Literals 
Swift :: waiting for all the threads to finish swift 
Swift :: parsing to double any data type in swift 
Swift :: swift open messages app 
Swift :: helen joseph 
ADD CONTENT
Topic
Content
Source link
Name
5+3 =