Asynchronous httpclient.getstringasync出现问题
我想为GuildWars 2开发一个Dragon Timer Windows应用商店应用程序。 不管怎样,我在sql数据库中保存了一个时间戳。为了在应用程序中获得这个时间戳,我制作了一个php脚本,将数据库的内容写入页面。现在我尝试通过HttpClient.GetStringAsync()方法接收该字符串。以下是截取的代码:Asynchronous httpclient.getstringasync出现问题,asynchronous,windows-runtime,microsoft-metro,windows-store-apps,dotnet-httpclient,Asynchronous,Windows Runtime,Microsoft Metro,Windows Store Apps,Dotnet Httpclient,我想为GuildWars 2开发一个Dragon Timer Windows应用商店应用程序。 不管怎样,我在sql数据库中保存了一个时间戳。为了在应用程序中获得这个时间戳,我制作了一个php脚本,将数据库的内容写入页面。现在我尝试通过HttpClient.GetStringAsync()方法接收该字符串。以下是截取的代码: async Task<Dictionary<String, DateTime>> GetKillTimes() { Dict
async Task<Dictionary<String, DateTime>> GetKillTimes()
{
Dictionary<String, DateTime> killTimes = new Dictionary<String,DateTime>();
HttpClient httpClient = new HttpClient();
Task<string> getStringTask = httpClient.GetStringAsync("http://www.wp10454523.server-he.de/truhentimer/getTimes.php");
String rawKillTimes = await getStringTask;
//Parse to Dictionary...
return killTimes;
}
异步任务GetKillTimes()
{
Dictionary kiltimes=新字典();
HttpClient HttpClient=新HttpClient();
任务getStringTask=httpClient.GetStringAsync(“http://www.wp10454523.server-he.de/truhentimer/getTimes.php");
String rawKillTimes=等待getStringTask;
//解析到字典。。。
返回时间;
}
我尝试了从google(WebRequest…)获得的一些不同的方法,但每个方法都在Get部分卡住了。我是不是误解了功能?我是否应该获取页面的内容,这是一个简单的字符串?您必须使用
await
关键字,因为WinRT中的web请求和响应是异步的,所以您必须使用await
关键字<代码>在httpClient.GetStringAsync(…)之前等待
Task getStringTask=wait httpClient.GetStringAsync(“http://www.wp10454523.server-he.de/truhentimer/getTimes.php");
谢谢您的帮助。也许您错过了它,但是下一行的getStringTask
前面有wait
。这就是我在微软网页上找到它的原因。不管怎样,如果我尝试你的,我必须将任务
更改为字符串
(转换原因),它无论如何都会卡住。哦,糟糕,我尝试了你的代码我得到了结果Tequatl,2013-06-01 18:30:19,Golem,2013-06-01 18:30:17,Dschungelwurm,2013-06-01 17:30:17,Feuerelementar,2013-06-01 18:15:17,Klaue Jors,2013-06-01 18:38:17,德·泽施梅特勒,2013-06-01 18:45:17,
rawkiltimesvariable.嗯,谢谢。我好像把方法调用搞砸了。嗯,收到响应后告诉我。请同时检查您的互联网是否正常工作。您是否在Package.appxmanifest
文件的capability
选项卡中选择了Internet(客户端)
?
Task<string> getStringTask = await httpClient.GetStringAsync("http://www.wp10454523.server-he.de/truhentimer/getTimes.php");