Windows phone 7 WindowsPhone7上的HttpWebRequest
我尝试在WindowsPhone7项目中使用HttpWebRequest从web服务器加载数据 我成功地获取了一次数据。但是当我第二次尝试调用相同的方法来加载时,我得到了异常,我得到了消息:“这是当这个线程从当前函数返回s时要执行的下一个语句。” 我正在使用来自独立类的HttpWebRequest异步调用,并在Dispatcher中附加了一个OnCompleted事件来更新WindowsPhone7的UIWindows phone 7 WindowsPhone7上的HttpWebRequest,windows-phone-7,httpwebrequest,Windows Phone 7,Httpwebrequest,我尝试在WindowsPhone7项目中使用HttpWebRequest从web服务器加载数据 我成功地获取了一次数据。但是当我第二次尝试调用相同的方法来加载时,我得到了异常,我得到了消息:“这是当这个线程从当前函数返回s时要执行的下一个语句。” 我正在使用来自独立类的HttpWebRequest异步调用,并在Dispatcher中附加了一个OnCompleted事件来更新WindowsPhone7的UI enter code here private void RequestStrea
enter code here
private void RequestStreamCallBack(IAsyncResult asyncResut)
{
HttpWebRequest hwr = asyncResut.AsyncState as HttpWebRequest;
if (hwr != null)
{
Stream stream = hwr.EndGetRequestStream(asyncResut);//error on this row, InvalidOperationExceptioni
byte[] writeByte = System.Text.Encoding.UTF8.GetBytes(_postData);
stream.Write(writeByte, 0, writeByte.Length);
stream.Close();
allDone.Set();
}
}
我是否应该在用户每次单击按钮时强制触发一次更新调用?
在发送调用BeginGetRequestStream()之前,我尝试在代码中添加一个“isLoading”标志,但它不起作用,我仍然在回调函数中遇到异常。您可能在同一个
IAsyncResult
上调用了两次HttpWebRequest.EndRequestStream
:
InvalidOperationException - This method was called previously using asyncResult.
您可能希望在读取和关闭响应流后(而不是在写入请求流后)调用allDone.set
查看您的回调序列是否与示例匹配:
你得到了什么例外?我明白了。也许我会在一节课上进行组合和取样-_-#