在Silverlight,Windows Phone 7的项目我创建一个HttpWebRequest的,得到RequestStream,写的东西进入流,并得到响应,但我总是得到NotSupportedException异常:"System.Net.Browser.OHWRAsyncResult.AsyncWaitHandle抛出类型'System.NotSupportedException'的异常
我的生产代码要复杂得多,但我可以将其缩小到这一小段代码:
public class HttpUploadHelper
{
private HttpWebRequest request;
private RequestState state = new RequestState();
public HttpUploadHelper(string url)
{
this.request = WebRequest.Create(url) as HttpWebRequest;
state.Request = request;
}
public void Execute()
{
request.Method = "POST";
this.request.BeginGetRequestStream(
new AsyncCallback(BeginRequest), state);
}
private void BeginRequest(IAsyncResult ar)
{
Stream stream = state.Request.EndGetRequestStream(ar);
state.Request.BeginGetResponse(
new AsyncCallback(BeginResponse), state);
}
private void BeginResponse(IAsyncResult ar)
{
// BOOM: NotSupportedException was unhandled;
// {System.Net.Browser.OHWRAsyncResult}
// AsyncWaitHandle = 'ar.AsyncWaitHandle' threw an
// exception of type 'System.NotSupportedException'
HttpWebResponse …Run Code Online (Sandbox Code Playgroud)