Question

I have this errors on 'error List'.

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

I'm make an App WindowsPhone 7 with vb.net on VisualStudio 2010

i can't understand why. Thanks

Était-ce utile?

La solution 2

 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);
    }

Autres conseils

You can't due to the async nature of WP. It seems like you have lifted examples from a non WP project. In WP, you have to make the call and then register an even that listens to the completion of the task. Further reading on Async Calls

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);
            }
        }
    }
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top