Как получить HTTP в Silverlight (Winphone)?
Мой код не работает (выдает исключения)
Я получаю следующие исключения:
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());
}
}