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