trong dự án Silverlight-Windows Phone 7 Tôi đang tạo HttpWebRequest, nhận RequestStream, viết nội dung nào đó vào Luồng và cố gắng nhận phản hồi, nhưng tôi luôn nhận được NotSupportedException : "System.Net.Browser.OHWRAsyncResult.AsyncWaitHandle ném một ngoại lệ của loại 'System.NotSupportedException'HttpWebRequest.EndGetResponse ném NotSupportedException trong Windows Phone 7
mã sản xuất của tôi là xa phức tạp hơn, nhưng tôi có thể thu hẹp nó xuống mảnh nhỏ mã này:
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 response = state.Request.EndGetResponse(ar) as HttpWebResponse;
Debug.WriteLine(response.StatusCode);
}
}
public class RequestState
{
public WebRequest Request;
}
}
Có ai biết điều gì sai với mã này không?
Xin chào Matt, tôi đang gặp phải sự cố tương tự. Xin vui lòng giúp đỡ, http://stackoverflow.com/questions/13598666/how-to-fix-system-argumentexception-in-httpwebresponse –