C# 如何在silverlight(Winphone)中获取HTTP
如何在silverlight(Winphone)中获取HTTP 我的代码不工作(抛出异常) 我得到以下例外情况:C# 如何在silverlight(Winphone)中获取HTTP,c#,.net,silverlight,windows-phone,C#,.net,Silverlight,Windows Phone,如何在silverlight(Winphone)中获取HTTP 我的代码不工作(抛出异常) 我得到以下例外情况: A first chance exception of type 'System.IO.FileNotFoundException' occurred in mscorlib.dll A first chance exception of type 'System.Net.ProtocolViolationException' occurred in System.Windows.d
A first chance exception of type 'System.IO.FileNotFoundException' occurred in mscorlib.dll
A first chance exception of type 'System.Net.ProtocolViolationException' occurred in System.Windows.dll
A first chance exception of type 'System.Net.ProtocolViolationException' occurred in System.Windows.dll
A first chance exception of type 'System.MissingMethodException' occurred in mscorlib.dll
A first chance exception of type 'System.Net.ProtocolViolationException' occurred in System.Windows.dll
代码如下:
public Boolean getAnnouncements()
{
try
{
string url = "https://server.james-bennet.com:8443/BookingSystem/Announcement";
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.Method = "GET";
request.Accept = "application/json";
request.ContentType = "application/json; charset=utf-8";
HttpWebResponse response = request.BeginGetResponse(new AsyncCallback(ReadCallback), request) as HttpWebResponse;
return true;
}
catch (Exception e)
{
System.Console.WriteLine(e.ToString());
return false;
}
}
private void ReadCallback(IAsyncResult asynchronousResult)
{
try
{
HttpWebRequest request = (HttpWebRequest)asynchronousResult.AsyncState;
HttpWebResponse response =(HttpWebResponse)request.EndGetResponse(asynchronousResult);
using (StreamReader streamReader1 = new StreamReader(response.GetResponseStream()))
{
string resultString = streamReader1.ReadToEnd();
System.Console.WriteLine(resultString);
}
}
catch (Exception e)
{
System.Console.WriteLine(e.ToString());
}
}
你确定你有吗
<Capability Name="ID_CAP_NETWORKING"/>
是否在WMAppManifest.xml文件中配置