swift post method

    //parameters
        let loginString = String(format: "email=%@&password=%@", userNameTF.text!, passwordTF.text!)
        
        let postData = loginString.data(using: .utf8)
    
        
        // create post request
        let url = URL(string: @"http://www.google.com")!
        var request = URLRequest(url: url)
        request.httpMethod = "POST"
        
        // insert json data to the request
        request.httpBody = postData
        
        let task = URLSession.shared.dataTask(with: request) { data, response, error in
            guard let data = data, error == nil else {
                print(error?.localizedDescription ?? "No data")
                return
            }
            let responseJSON = try? JSONSerialization.jsonObject(with: data, options: [])
            if let responseJSON = responseJSON as? [String: Any] {
                print(responseJSON)
            }
        }
        
        task.resume()
        

    }
Previous
Next Post »

1 comments:

Write comments
Anonymous
AUTHOR
30 January 2018 at 04:24 delete

https://iosdevcenters.blogspot.com/2016/11/how-to-change-uitexefield-placeholder.html

Reply
avatar