Hello all!
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.
I also had to create an asp.net website to post data to the Windows Forms application. This is working perfectly.
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.
if (System.Net.NetworkInformation.NetworkInterface.GetIsNetworkAvailable() && 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);
}
}
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.
I cannot upload an image to this website it seems, so I shall upload it to a FreeWebs site - sorry, really embarrassing! watch.jpg
As you can see, I am getting System.NotSupported on datastream.Length and datastream.Position
Could you please help me to fix this? Thanks!
Just in case an asp.net programmer also sees this, is there any problem with this receiving code?:
protected void Page_Load(object sender, EventArgs e)
{
string test = Request.BinaryRead(Request.TotalBytes).ToString();
}
Thank you all, so, so much for your time!
Richard
EDIT: In relation to gandjustas's comment, I am providing more information.
Something in the chain is not working. I am not getting any formal exceptions to report.
If I use this code in the asp.net webpage:
string test = Request.BinaryRead(Request.TotalBytes).ToString();
Response.Clear();
Response.Write(test);
Response.End();
I get the following response back: System.Byte[]
This is not a variable, but a string containing the arbitrary words and symbols 'System.Byte[]'
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.
I kind of need help. Thanks!