Skip to content

Instantly share code, notes, and snippets.

@hongry18
Created February 3, 2017 01:07
Show Gist options
  • Save hongry18/eefad64c969cdacca758394fe73a696b to your computer and use it in GitHub Desktop.
Save hongry18/eefad64c969cdacca758394fe73a696b to your computer and use it in GitHub Desktop.
request swift 3
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