Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/windows-phone-7/3.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
Vb.net WP7应用程序WebRequest出错_Vb.net_Windows Phone 7_Webrequest - Fatal编程技术网

Vb.net WP7应用程序WebRequest出错

Vb.net WP7应用程序WebRequest出错,vb.net,windows-phone-7,webrequest,Vb.net,Windows Phone 7,Webrequest,我在“错误列表”中有此错误 'ContentLength' is not a member of 'System.Net.WebRequest' 'GetRequestStream' is not a member of 'System.Net.WebRequest' 'GetResponse' is not a member of 'System.Net.WebRequest' 我正在VisualStudio2010上用vb.net制作一个WindowsPhone 7应用程序 我不明白为

我在“错误列表”中有此错误

'ContentLength' is not a member of 'System.Net.WebRequest'

'GetRequestStream' is not a member of 'System.Net.WebRequest'

'GetResponse' is not a member of 'System.Net.WebRequest'
我正在VisualStudio2010上用vb.net制作一个WindowsPhone 7应用程序


我不明白为什么。谢谢

由于WP的异步特性,您不能这样做。看起来你从一个非WP项目中摘取了一些例子。在WP中,您必须拨打电话,然后注册一个偶数,以监听任务的完成情况。进一步阅读

private void GetSource(object sender, RoutedEventArgs e)
    {
        System.Net.WebRequest request = WebRequest.Create("http://www.bbc.co.uk");
        //request.ContentType = "application/json";
        request.Method = "GET";

        request.BeginGetResponse(new AsyncCallback(GetResponseCallback), request);
    }

 private void GetResponseCallback(IAsyncResult asynchronousResult)
    {
        var request = asynchronousResult.AsyncState as HttpWebRequest;

        if (request != null)
        {
            try
            {
                WebResponse response = request.EndGetResponse(asynchronousResult);
                using (Stream stream = response.GetResponseStream())
                {
                    using (var reader = new StreamReader(stream, Encoding.UTF8))
                    {
                        var responseString = reader.ReadToEnd();

                        MessageBox.Show(responseString);
                    }                      
                }
            }
            catch (WebException e)
            {
               // Handle exception
                MessageBox.Show(e.Message);
            }
        }
    }
 public void SendPost(Uri uri, string json)
    {
    var webClient = new WebClient();
    webClient.Headers[HttpRequestHeader.ContentType] = "application/json";
    webClient.UploadStringCompleted += this.sendPostCompleted;
    webClient.UploadStringAsync(uri, "POST", json);
    }