我正在尝试使用以下代码启动 WP7 测试:
var client = new RestClient("http://google.com");
var request = new RestRequest(Method.GET);
client.ExecuteAsync(request, response => Debug.WriteLine(response.StatusCode);
此代码写入 HttpStatusCode=0 并引发错误:
'System.Net.WebRequest' 的类型初始化程序引发了异常。System.TypeInitializationException
如何解决?
更新#1
例如,此代码在 Windows 类库中运行良好,但在 Silverlight 和 WP7 项目中不起作用:
var client = new RestClient("http://carma.org/api/1.1/searchPlants");
var request = new RestRequest();
request.AddParameter("location", 4338);
request.AddParameter("limit", 10);
request.AddParameter("color", "red");
request.AddParameter("format", "xml");
var plants = client.ExecuteAsync(
request, response => Assert.AreEqual(HttpStatusCode.OK, response.StatusCode));