Search
 
SCRIPT & CODE EXAMPLE
 

SWIFT

ios make http request

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()
}
Comment

PREVIOUS NEXT
Code Example
Swift :: swift get current hour 
Swift :: how to set the font of text in swiftui 
Swift :: swift scrollview auto fit content height 
Swift :: xcode how to know which textfield is selected 
Swift :: check notification permission ios swift 
Swift :: Equatable Function Swift 
Swift :: how can i find range of a string in another string swift 
Swift :: swift sort list true before false 
Swift :: UIFont.init bold 
Swift :: Play Video in AVPlayer ViewController Sample Code Swift 
Swift :: swift extension Array with type 
Swift :: Single Line Comment 
Swift :: Swift guard-let Statement 
Swift :: how to change background color swift 
Swift :: swift firebase realtime db class 
Swift :: swift go to main thread 
Swift :: swift from 1 to 01 
Swift :: Swift static Methods 
Swift :: Swift is case-sensitive. So A and a are different variables 
Swift :: Swift Nested Ternary Operators 
Swift :: cherries 
Swift :: Computed Property In Extension Swift 
Swift :: Swift guard with multiple conditions 
Swift :: Swift Variables names must start with either a letter 
Swift :: swift float 
Swift :: swiftui show custom loading spinner 
Swift :: swift ge array item from indexset 
Ruby :: ruby sort an object 
Ruby :: remove ruby 
Ruby :: rspec add support folder to gem 
ADD CONTENT
Topic
Content
Source link
Name
4+2 =