Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you get all the post request variables in C#?

Tags:

c#

asp.net

I am getting a post from an external vendor. I am not exactly sure what variables they are sending. How do I print out all the Request variables that they are sending in the post? there is no Request.Count or Request.Length so that I could loop and find everything.

Thanks in advance for your help.

like image 656
Greg Finzer Avatar asked Jul 13 '12 20:07

Greg Finzer


2 Answers

The Request.Form property contains a collection with all form fields. It is a NameValueCollection which implements ICollection so you should be able to loop it with foreach. Request.Form.Keys will give you all the form field names, then you can use that name to look up the value.

foreach(string key in Request.Form.Keys)
{
  Response.Write(key + ": " + Request.Form[key] + "<br/>");
}
like image 199
Anders Abel Avatar answered Sep 22 '22 07:09

Anders Abel


You can get it from Request.Forms

foreach(string key in Request.Form.Keys ) 
{
  Response.Write ( key );
}
like image 42
Waqar Janjua Avatar answered Sep 19 '22 07:09

Waqar Janjua