2. Request GET
페이지 정보
작성자 관리자 댓글 0건 조회 3,753회 작성일 20-02-11 16:48본문
2. Request GET
guard let url = URL(string: "https://www.leelab.co.kr/item/getItems.php") else {return }
var request = URLRequest(url: url)
request.httpMethod = "GET"
request.addValue("application/json", forHTTPHeaderField: "Content-Type")
request.addValue(token, forHTTPHeaderField: "Authorization")
let session = URLSession.shared
session.dataTask(with: request) { (data, response, error) in
guard error == nil else {
print(" >> error (1)")
return
}
guard let data = data else {
print(" >> error (2)")
return
}
do {
if let json = try JSONSerialization.jsonObject(with: data, options: JSONSerialization.ReadingOptions.mutableContainers) as? [String : Any] {
//print(json)
let code = json["code"] as! Int
if code == 200 {
DispatchQueue.main.async {
self.createTransaction()
}
}else {
DispatchQueue.main.async {
print( "Item is not found.")
}
}
}
}catch let error {
print(error.localizedDescription)
}
}.resume()
댓글목록
등록된 댓글이 없습니다.