Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/298.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在silverlight(Winphone)中获取HTTP_C#_.net_Silverlight_Windows Phone - Fatal编程技术网

C# 如何在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

如何在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文件中配置