C# 创建(MSDN示例)
我尝试为json创建一个简单的webrequest,我尝试使用MSDN上的示例C# 创建(MSDN示例),c#,silverlight,C#,Silverlight,我尝试为json创建一个简单的webrequest,我尝试使用MSDN上的示例 // Create a new 'Uri' object with the specified string. Uri myUri =new Uri("http://www.contoso.com"); // Create a new request to the above mentioned URL. WebRequest myWebRequest= WebReq
// Create a new 'Uri' object with the specified string.
Uri myUri =new Uri("http://www.contoso.com");
// Create a new request to the above mentioned URL.
WebRequest myWebRequest= WebRequest.Create(**myUri**);
// Assign the response object of 'WebRequest' to a 'WebResponse' variable.
WebResponse myWebResponse= **myWebRequest**.GetResponse();
我得到以下错误
字段初始值设定项不能引用非静态字段、方法或属性
在高亮显示的对象上。(myUri和myWebRequest)有什么想法吗
谢谢,这不起作用,因为Silverlight中的所有内容都必须是异步的。它们强制执行此操作,因为主线程上的所有执行(如webrequest)都会锁定UI。这种方法提供了更好的用户体验,是让开发人员掌握线程在基本开发活动中的使用的一种折衷方法 见此: