Created
January 17, 2019 11:58
-
-
Save codemodify/c52ae6cc010b6bd372284c951028948a to your computer and use it in GitHub Desktop.
qosmicparticles-io-samples.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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