0
iOS 애플리케이션에서 마젠타 색 REST API에 액세스하려고합니다.iOS의 Magento Rest API에 액세스 - 스위프트 3.0
func getCustomerTokenusingURLSEssion(){
let url = URL(string: "HTTPURL")!
var urlRequest = URLRequest(
url: url,
cachePolicy: .reloadIgnoringLocalAndRemoteCacheData,
timeoutInterval: 10.0 * 1000)
urlRequest.httpMethod = "POST"
urlRequest.addValue("application/json", forHTTPHeaderField: "Accept")
let json1: [String: Any] = [
"username": "[email protected]",
"password":"xyz12345"]
let jsonData = try? JSONSerialization.data(withJSONObject: json1, options: .prettyPrinted)
urlRequest.httpBody = jsonData
let config = URLSessionConfiguration.default
let urlsession = URLSession(configuration: config)
let task = urlsession.dataTask(with: urlRequest){ (data, response, error) -> Void in
print("response from server: \(response)")
guard error == nil else {
print("Error while fetching remote rooms: \(error)")
return
}
guard let data = data,
let json = try? JSONSerialization.jsonObject(with: data) as? [String: Any] else {
print("Nil data received from fetchAllRooms service ")
return
}
print("JSON \(json)")
}
task.resume()
}
하지만 오류 메시지는 다음과 같은 서버를 형성 받고 있어요 : 다음 는 API에 액세스하려면 코드입니다
[ "메시지"의 Content-Type HTTP 헤더 미디어 유형을 이해할 수없는 서버 application/x-www-form-urlencoded]
도와주세요! 감사합니다.