我有一個受用戶名和密碼保護的網站。 我需要獲取XML文件,然後解析它。我嘗試了許多解決方案,但沒有一個爲我工作。我得到這個代碼。Swift + Alamofire - 驗證並獲取XML文件
Error: Error Domain=NSCocoaErrorDomain Code=3840 "The operation couldn’t be completed. (Cocoa error 3840.)" (Encountered unknown tag tabless on line 1) UserInfo=0x1aadf300 {NSDebugDescription=Encountered unknown tag tabless on line 1, kCFPropertyListOldStyleParsingError=The operation couldn’t be completed. (Cocoa error 3840.)}
這裏是我的代碼:
func getTimeStampOfUpdatedTables(completionHandler: (Bool) ->()) ->(){
let user = "abc"
let password = "abc"
let plainString = "\(user):\(password)" as NSString
let plainData = plainString.dataUsingEncoding(NSUTF8StringEncoding)
let base64String = plainData?.base64EncodedStringWithOptions(NSDataBase64EncodingOptions(rawValue: 0))
Alamofire.Manager.sharedInstance.session.configuration.HTTPAdditionalHeaders = ["Authorization": "Basic " + base64String!]
Alamofire.request(.GET, "http://example.com/info.php", encoding: ParameterEncoding.URL).responsePropertyList { response in
print(response.result)
if let error = response.result.error {
print("Error: \(error)")
// parsing the data to an array
} else if let array = response.result.value as? [[String: String]] {
if array.isEmpty {
print("No data")
} else {
//Do whatever you want to do with the array here
print("data here!")
}
}
}
}
如何處理dicsParams? –
discParam是一個參數字典。 –
是的,但在您提供的代碼中沒有此字典的標識符。 –