title: Problems POSTing data to an asp.net webpage (problem in Desktop C# end)
body: <p>Thank you so much for taking the time to read my post! I am having a problem POSTing data from a C# Desktop application to a C# asp.net web page. I believe that the problem lies in the Desktop application (or at least one of the problems does!) I will also post the asp.net code I am using. If asp.net is not your speciality, don't worry, I was just wondering if there was anything glaringly obvious there as well. </p>
  
  <p>I also had to create an asp.net website to post data to the Windows Forms application. This is working perfectly. </p>
  
  <p>Here is the code I am using. What is not working is discussed below. I am very bad at all this asp.net stuff, so any help you can provide would be very much appreciated.</p>
  
  <pre><code>if (System.Net.NetworkInformation.NetworkInterface.GetIsNetworkAvailable() &amp;&amp; result == DialogResult.Yes)
              {
                  string test = "Test";
                  WebRequest request = WebRequest.Create("http://localhost/test.aspx");
                  byte[] byteArray = Encoding.UTF8.GetBytes(test);
  
                  request.Method = "POST";
                  request.ContentType = "application/x-www-form-urlencoded";
                  request.ContentLength = byteArray.Length;
  
                  // Give the response
                  using (Stream datastream = request.GetRequestStream())
                  {
                      datastream.Write(byteArray, 0, byteArray.Length);
                  }
               }
  </code></pre>
  
  <p>However, when I Debug the application, and put a breakpoint just after datastream.Write() I get some errors in the Variable Watch window. I do not get any exceptions except in there. </p>
  
  <p>I cannot upload an image to this website it seems, so I shall upload it to a FreeWebs site - sorry, really embarrassing! <a href="http://rjnb.webs.com/watch.JPG" rel="nofollow">watch.jpg</a></p>
  
  <p>As you can see, I am getting System.NotSupported on datastream.Length and datastream.Position</p>
  
  <p>Could you please help me to fix this? Thanks!</p>
  
  <p>Just in case an asp.net programmer also sees this, is there any problem with this receiving code?: </p>
  
  <pre><code>    protected void Page_Load(object sender, EventArgs e)
      {
          string test = Request.BinaryRead(Request.TotalBytes).ToString();
      }
  </code></pre>
  
  <p>Thank you all, so, so much for your time!</p>
  
  <p>Richard</p>
  
  <p>EDIT: In relation to gandjustas's comment, I am providing more information. </p>
  
  <p>Something in the chain is not working. I am not getting any formal exceptions to report. </p>
  
  <p>If I use this code in the asp.net webpage:             </p>
  
  <pre><code> string test = Request.BinaryRead(Request.TotalBytes).ToString();
  
          Response.Clear();
          Response.Write(test);
          Response.End();
  </code></pre>
  
  <p>I get the following response back: System.Byte[]</p>
  
  <p>This is not a variable, but a string containing the arbitrary words and symbols 'System.Byte[]'</p>
  
  <p>Something is not working (obviously) I then see this System.NotSupportedException in my Watch window. This make me think that there are two errors: This System.NotSupportedException needs fixing in my C# Desktop Application, and my asp.net webpage should not be displaying System.Byte[] before I have even sent my POST from the application.</p>
  
  <p>I kind of need help. Thanks!</p>