Note that there are some explanatory texts on larger screens.

plurals
  1. POHttpWebRequest.GetResponse() throws WebException
    text
    copied!<p>I am using the latest version of Monodroid, 4.04, and am trying to connect to a device using HttpWebRequest. The problem I am running into is the GetResponse is throwing a webexception (see below). In the debugger, when I set a breakpoint, I can see that webRequest.HaveResponse == true, but the response is null in the exception. </p> <p>Why can't I get to the response when it reports that has a response?</p> <p>The code I am using:</p> <pre><code>string responseFromServer; ServicePointManager.CertificatePolicy = new TestCertificatePolicy(); HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create("https://192.168.1.1/login.cgi"); webRequest.KeepAlive = true; webRequest.Method = "POST"; webRequest.ContentType = "application/x-www-form-urlencoded"; webRequest.ContentLength = byteArray.Length; webRequest.ReadWriteTimeout = 10000; // Get the request stream. Stream dataStreamIn = webRequest.GetRequestStream(); dataStreamIn.Write(byteArray, 0, byteArray.Length); dataStreamIn.Close(); try { WebResponse response = webRequest.GetResponse(); &lt;-- throws webexception Stream dataStream = response.GetResponseStream(); StreamReader reader = new StreamReader(dataStream); responseFromServer = reader.ReadToEnd(); Console.WriteLine(responseFromServer); reader.Close(); dataStream.Close(); response.Close(); Console.WriteLine("Done"); } catch (WebException we) { Console.WriteLine(we); throw; } </code></pre> <p>Here is the exception:</p> <pre><code>System.Net.WebException: Error getting response stream (ReadDone2): ReceiveFailure ---&gt; System.Exception: at System.Net.WebConnection.ReadDone(IAsyncResult result) at System.Net.WebConnection.HandleError (WebExceptionStatus st, System.Exception e, System.String where) [0x0003a] in /home/jon/Development/xamarin/mono/mcs/class/System/System.Net/WebConnection.cs:399 --- End of inner exception stack trace --- at System.Net.HttpWebRequest.EndGetResponse (IAsyncResult asyncResult) [0x0005e] in /home/jon/Development/xamarin/mono/mcs/class/System/System.Net/HttpWebRequest.cs:828 at System.Net.HttpWebRequest.GetResponse () [0x0000e] in /home/jon/Development/xamarin/mono/mcs/class/System/System.Net/HttpWebRequest.cs:836 at MonoDroidTest.Activity1.GetStreamPage (System.String url) [0x000c2] in C:\Users\dave\Documents\Visual Studio 2010\Projects\MonoDroidTest\MonoDroidTest\Activity1.cs:277 </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload