Estoy tratando de hacer un HTTP (S) POST asíncrono en .NET Compact Framework y parece que no puedo hacer que funcione.WebRequest asíncrono con parámetros POST en .NET Compact Framework
Esto es lo que estoy haciendo:
private void sendRequest(string url, string method, string postdata) {
WebRequest rqst = HttpWebRequest.Create(url);
CredentialCache creds = new CredentialCache();
creds.Add(new Uri(url), "Basic", new NetworkCredential(this.Uname, this.Pwd));
rqst.Credentials = creds;
rqst.Method = method;
if (!String.IsNullOrEmpty(postdata)) {
rqst.ContentType = "application/xml";
byte[] byteData = UTF8Encoding.UTF8.GetBytes(postdata);
rqst.ContentLength = byteData.Length;
using (Stream postStream = rqst.GetRequestStream()) {
postStream.Write(byteData, 0, byteData.Length);
postStream.Close();
}
}
((HttpWebRequest)rqst).KeepAlive = false;
rqst.BeginGetResponse(DataLoadedCB, rqst);
}
private void DataLoadedCB(IAsyncResult result) {
WebRequest rqst = ((WebRequest)(((BCRqst)result.AsyncState).rqst));
WebResponse rsps = rqst.EndGetResponse(result);
/* ETC...*/
}
... pero por alguna razón me siento un WebException en la segunda fila de DataLoadedCB:
"Esta solicitud requiere almacenamiento temporal de los datos de autenticación o redirección para tener éxito ".
El mismo código funciona perfectamente, cuando hago un simple HTTP GET, pero cuando incluyo algunos parámetros POST, todo falla.
¿Alguna idea?
supongo que quiere decir añadir este (RQST (HttpWebRequest)) cerca de .KeepAlive ** = false; ** :) –