如何在silverlight(Winphone)中实现HTTP
本文关键字:实现 HTTP Winphone silverlight | 更新日期: 2023-09-27 18:29:48
如何在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.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文件中配置?