我想在我的C#WinRT代码中为httpwebrequest设置超时值。但httpwebrequest在WinRT中不可用。那么请告诉我如何设置HttpWebRequest的超时值。
答案 0 :(得分:1)
使用HttpClient课程提出请求。它有一个TimeOut属性,您可以根据自己的喜好进行设置。
您也可以使用HttpWebRequest类,它也有TimeOut属性。
在大多数情况下,HttpClient是最佳选择,因为它更易于使用,并且您不需要HttpWebRequest提供的自定义级别。
答案 1 :(得分:0)
要为您的webrequest设置超时,您需要设置HttpWebRequest.Timeout以及所有内容。
//get the path of the plist file
guard let plistPath = Bundle.main.path(forResource: "elements", ofType: "plist") else { return }
print("plistPath:", plistPath)
//load the plist as data in memory
guard let plistData = FileManager.default.contents(atPath: plistPath) else { return }
print("plistData:", plistData)
//use the format of a property list (xml)
var format = PropertyListSerialization.PropertyListFormat.xml
//convert the plist data to a Swift Dictionary
guard let plistDict = try! PropertyListSerialization.propertyList(from: plistData, options: .mutableContainersAndLeaves, format: &format) as? [String : AnyObject] else { return }
print("plistDict:", plistDict)
//access the values in the dictionary
if let value = plistDict["DescrizioneEsercizio"] as? String {
//do something with your value
print(value)
}