2017-08-29 110 views

回答

0

您需要對查詢字符串進行編碼,然後使用包含baseURL和查詢的標頭和URL創建URLRequest。最後,您需要撥打dataTask來執行您的請求。

let baseUrl = "https://parseapi.back4app.com/classes/RESTAURANT" 
guard let queryParameters = "where={\"Area\":\"Vesu\"}".addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed) else {return} 
guard let url = URL(string: baseUrl+"?"+queryParameters) else {return} 
var urlRequest = URLRequest(url: url) 
urlRequest.allHTTPHeaderFields = ["X-Parse-Application-Id":"XXXX", "X-Parse-REST-API-Key":"XXXX"] 
URLSession.shared.dataTask(with: urlRequest, completionHandler: { data, response, error in 
    guard error == nil else { 
     print(error!); return 
    } 
    //handle data and/or response 
}).resume()