Skip to content

Instantly share code, notes, and snippets.

@codemodify
Created January 17, 2019 11:58
Show Gist options
  • Save codemodify/c52ae6cc010b6bd372284c951028948a to your computer and use it in GitHub Desktop.
Save codemodify/c52ae6cc010b6bd372284c951028948a to your computer and use it in GitHub Desktop.
qosmicparticles-io-samples.swift
import Foundation
let headers = [
"Content-Type": "application/json",
]
let parameters = [
"version": "2.0",
"key": "rcd1JN+CkZo2+KKR802bXTujubMbiZARQcyTR8Ku8haqdyaz8pA8Z1kbrWJO2J2CiwFdnr",
"gobSize": 10
] as [String : Any]
let postData = JSONSerialization.data(withJSONObject: parameters, options: [])
let request = NSMutableURLRequest(url: NSURL(string: "http://qosmicparticles.io::4444/FetchGobs")! as URL,
cachePolicy: .useProtocolCachePolicy,
timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data
let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
if (error != nil) {
print(error)
} else {
let httpResponse = response as? HTTPURLResponse
print(httpResponse)
}
})
dataTask.resume()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment