Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var request = URLRequest(url: URL(string: "https://api.thingspeak.com/update")!)
- request.httpMethod = "POST"
- let postString = "api_key=H3MQFPAJ1IOK1I0W&field1=2"
- request.httpBody = postString.data(using: .utf8)
- let task = URLSession.shared.dataTask(with: request) { data, response, error in
- guard let data = data, error == nil else {
- print("error=\(error)")
- return
- }
- if let httpStatus = response as? HTTPURLResponse, httpStatus.statusCode != 200 {
- print("statusCode should be 200, but is \(httpStatus.statusCode)")
- print("response = \(response)")
- }
- let responseString = String(data: data, encoding: .utf8)
- print("responseString = \(responseString)")
- }
- task.resume()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement