Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1090693
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T23:24:41+00:00 2026-05-16T23:24:41+00:00

Thank you so much for taking the time to read my post! I am

  • 0

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!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T23:24:42+00:00Added an answer on May 16, 2026 at 11:24 pm

    Couple of remarks about your code:

    1. You are setting application/x-www-form-urlencoded content type but you are sending some arbitrary byte array. When you set this content type the server will expect that the request is encoded using it.
    2. The NotSupportedException you are getting in the Debug window are normal. You simply cannot use the Length property on a NetworkStream.

    Let me try to simplify your code in case you really want to use application/x-www-form-urlencoded:

    Client:

    using (var client = new WebClient())
    {
        var values = new NameValueCollection
        {
            { "key1", "value1" },
            { "key2", "value2" },
        };
        byte[] result = client.UploadValues("http://example.com/test.aspx", values);
    }
    

    Server:

    protected void Page_Load(object sender, EventArgs e)
    {
        string key1 = Request["key1"];
        string key2 = Request["key2"];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have spent too much time on this problem and am beginning to think
Since some time, my Delphi debugger became much slower than I was used to
If yes, when? and how much time do you think that the process will
It's shown that 'as' casting is much faster than prefix casting, but what about
I think the title pretty much says it all... I'm looking to implement an
How much less libraries are there for Mono than for Java? I lack the
The examples I've seen online seem much more complex than I expected (manually parsing
I find it much easier to write MXML classes with embedded Script than trying
I now have it set up so that when people go to a thank
What is the SQL query to select all of the MSSQL Server's logins? Thank

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.