I am attempting to connect to a MySQL database with Swift through PHP by getting the HTML of a PHP script. I plan on using the URL to pass variables such as username, password, or id to the PHP script then call the MySQL. However, whenever I attempt to get the response of a webpage with NSURL
an error occurs. Here is the code I am using:
let myUrl = NSURL(string: "http://www.google.com")
let request = NSMutableURLRequest(URL: myUrl!)
request.HTTPMethod = "POST"
let task = NSURLSession.sharedSession().dataTaskWithRequest(request) {
data, response, error in
let responseString = NSString(data: data!, encoding: NSUTF8StringEncoding)
if error != nil {
print("Error: \(error)")
}
print("Response: \(response)")
print("Response String: \(responseString)")
}
task.resume()
Do I need to format the output from the website to be properly transferred to Swift? Thank you for the help.