0

我在“错误列表”上有这个错误。

'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'

我正在 VisualStudio 2010 上使用 vb.net 制作应用程序 WindowsPhone 7

我不明白为什么。谢谢

4

2 回答 2

1

由于 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);
            }
        }
    }
于 2013-10-10T14:15:26.440 回答
0
 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);
    }
于 2013-10-15T13:45:38.403 回答