2014-06-23 78 views
1

我有这样的代码,可以在VS2012的桌面控制台项目中使用,但不适用于WP8的VS2013。链接不在Windows Phone 8.1中打开

url = "http://lenta.ru/photo/2014/06/23/blackwidow/" 

WebRequest request = WebRequest.Create(url); 
WebResponse response = await request.GetResponseAsync(); /*from here programm doesn't work on wp8, but works on PC Console Project on VS2012*/ 
Stream data = response.GetResponseStream(); 

为什么此代码在控制台项目上工作,但不能从我的WP8应用程序工作?

修复。 问题通过使用HttpCLient而不是WebRequest来解决。

HttpClient client = new HttpClient(); 
try 
{ 
    var result = await client.GetStringAsync(url); 
} 
catch 
{ 

} 
client.Dispose(); 
+0

请确保你正确标记你的问题 –

+0

我已经通过使用HttpClient解决了这个问题。 – FruitDealer

+1

如果您解决了您的问题,请务必在下面发布。这不是你的个人Q和A ...这是为每个人记录常见问题和解决方案。其他人将来可能会遇到这个问题。 –

回答

0

问题通过使用HttpCLient而不是WebRequest来解决。

HttpClient client = new HttpClient(); 
try 
{ 
    var result = await client.GetStringAsync(url); 
} 
catch 
{ 

} 
client.Dispose();