Not sure if this has solved the issue, but it seems more stable since I
added ((HttpWebRequest)webRequest).KeepAlive = false;

 

 

private string getData(string url, Boolean postData, String xmlData)

        {

            String responseFromServer=string.Empty;

            try

            {

                // Create a request using a URL that can receive a post.


                WebRequest webRequest = WebRequest.Create(url);

                {

                    try

                    {

                        ((HttpWebRequest)webRequest).KeepAlive = false;
//<<<=====New test idea!!!!

                        webRequest.Timeout = 2000 * 60; //Two minutes

                        if (postData)

                        {

                            // Set the Method property of the request to
POST.

                            webRequest.Method = "POST";

                            // Create POST data and convert it to a byte
array.

                            byte[] byteArray =
Encoding.ASCII.GetBytes(xmlData);

                            // Set the ContentType property of the
WebRequest.

                            webRequest.ContentType = "text/plain";

                            // Set the ContentLength property of the
WebRequest.

                            webRequest.ContentLength = byteArray.Length;

                            // Get the request stream.

                            using (Stream dataStream =
webRequest.GetRequestStream())

                            {

                                dataStream.Write(byteArray, 0,
byteArray.Length);

                            }

                        }

                    }

                    catch { 

                    }

                    // Get the response.

                    using (WebResponse response =
webRequest.GetResponse())

                    {

 
Console.WriteLine(((HttpWebResponse)response).StatusDescription);

                        // Get the stream containing content returned by
the server.

                        using (Stream responseStream =
response.GetResponseStream())

                        {

                            using (StreamReader reader = new
StreamReader(responseStream))

                            {

                                responseFromServer = reader.ReadToEnd();

                            }

                        }

                    }

                }

            }

            catch (Exception ex)

            {

                System.Diagnostics.StackTrace stackTrace = new
System.Diagnostics.StackTrace();

                String method = stackTrace.GetFrame(0).GetMethod().Name;

                log.writeLogInfo("ERROR " + method + ":", ex.Message +
"\n" + ex.StackTrace.ToString());

            }

            return responseFromServer;

        }

 

_______________________________________________
Monodroid mailing list
Monodroid@lists.ximian.com

UNSUBSCRIBE INFORMATION:
http://lists.ximian.com/mailman/listinfo/monodroid

Reply via email to