Ali_dotNet
Ali_dotNet

Reputation: 3279

reading posted values in ASP.NET

I'm going to create a post test server, something like: http://www.posttestserver.com/

I'm using a hardware device to send remote data to my system via HTTP post, then I want to receive the posted data, I've tested several methods to read data posted from this device but I had no luck. But the site mentioned above could get data posted by device, here is the code I've used to get posted data:

            System.Text.StringBuilder displayValues =
            new System.Text.StringBuilder();
        System.Collections.Specialized.NameValueCollection
            postedValues = Request.Form;
        String nextKey;
        Response.Write(postedValues.AllKeys.Length.ToString());
        for (int i = 0; i < postedValues.AllKeys.Length; i++)
        {
            nextKey = postedValues.AllKeys[i];
            if (nextKey.Substring(0, 2) != "__")
            {
                displayValues.Append("<br>");
                displayValues.Append(nextKey);
                displayValues.Append(" = ");
                displayValues.Append(postedValues[i]);
            }
        }

what is going wrong? I set my page url in device and then try to post data, but I get nothing

Upvotes: 0

Views: 110

Answers (1)

Woland
Woland

Reputation: 2919

Are you posting to the correct page, can you attach to IIS process and put a break point? You can also use a http://fiddler2.com/ tool to see what kind of post is generated.

Your code looks fine, does the Response.Write(postedValues.AllKeys.Length.ToString()); display anything or simply 0?

Upvotes: 1

Related Questions