в Silverlight-Windows Phone 7-project Я создаю HttpWebRequest, получаю RequestStream, пишу что-то в Stream и пытаюсь получить ответ, но всегда получаю исключение NotSupportedException : «System.Net.Browser.OHWRAsyncResult.AsyncWaitHandle бросил исключение типа„System.NotSupportedException“HttpWebRequest.EndGetResponse вызывает исключение NotSupportedException в Windows Phone 7
Мой код продукции гораздо сложнее, но я могу сократить его до этой небольшой кусок кода:
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;
}
Кто-нибудь знает, что не так с этим кодом?
Привет, Мэтт, я столкнулся с подобной проблемой. Пожалуйста, помогите, http://stackoverflow.com/questions/13598666/how-to-fix-system-argumentexception-in-httpwebresponse –