Created
February 3, 2017 01:07
-
-
Save hongry18/eefad64c969cdacca758394fe73a696b to your computer and use it in GitHub Desktop.
request swift 3
This file contains 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
func _request(url: String, data: String) -> Void { | |
var req = URLRequest(url: URL(string: url)!) | |
req.httpMethod = "POST" | |
req.httpBody = data.data(using: String.Encoding.utf8) | |
//let session = URLSession.shared | |
let session = URLSession(configuration: URLSessionConfiguration.default) | |
let task = session.dataTask(with: req) {data, response, error in | |
if error != nil { | |
print(error!) | |
// 에러 콜백 | |
return | |
} | |
print(String(data: data!, encoding: String.Encoding.utf8)!) | |
// 완료 콜백 | |
} | |
task.resume() | |
} | |
/* | |
using | |
let dict = [ | |
"input": [ | |
"input": [["user_id": ""]], | |
"VC": [ | |
"input":[["COL": ""]] | |
] | |
] | |
] as [String : Any] | |
_request(url: "http://pjh.kodeit.co.kr/service/db/test1/", data: "data=\(dict.dict2json())") | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment