HTML POST

  • Thread starter Thread starter Thom Little
  • Start date Start date
T

Thom Little

I have an HTML Form that uses GET and is processed by an ASP.NET 1.1 web
application.

Can you recommend a simple example of an HTML Form that uses POST and is
processed by an ASP.NET web application (either 1.1 or 2.0)?

What was the source of your information?

Thank you.
 
GET requires that the data be extracted from a querystring (because that how
GET causes the data to be transmitted).

i..e. x = Request.QueryString("txtUser")

POST allows you to simply ask for a specific piece of data by the name of
the control that contrained it before the data was posted.

i.e. x = txtUser.Text
 
I was apparently confusing. I have been using GET and want to revise the
mechanism to use POST.

The form in question is an HTML form located on an .asp or .html (not .aspx)
page and invokes an .aspx page to process the form.

What I need is an example of trivial processing in the .aspx module that
accesses the data passed to it by the .asp or .html module.
 
Since you aren't on a 100% .NET platform, it really doesn't matter which you
sent it with (GET or POST), the Request object can retrieve either (just has
always been the case in classic asp).

Just use:

Request(theFormItemName)
 
Thanks for the lead. Your cryptic reply assumes a lot more competence on my
part then actually exists. I really didn't know how it fit together.

With your hit and another lead from the wonderful Code Project I changed my
existing ...

NameValueCollection nvcQuery = Request.QueryString ;

... to ...

NameValueCollection nvcQuery ;
if ( Context.Request.Form.Count != 0 )
nvcQuery = Request.Form ;
else
nvcQuery = Request.QueryString ;

.... and this allows me to call the page using either GET or POST on the form
and process each paramater like ...

nvcQuery["firstname"]

Now I can convert my forms to POST and somewhat hide the values being
passed.

Thanks.
 
You really don't need to go through all of that.

Request.Form(formItemName) will extract data out of the Forms collection
(used when form data is sent via POST)

Request.QueryString(formItemName) will extract data out of the QueryString
collection (used when form data is sent via GET)

Request(formItemName) will extract data from EITHER the Forms or QueryString
collection (regardless of where it is).

So, you don't need to check to see whether the data is in the Forms or
QueryString you can just write: nvcQuery["firstname"]




Thom Little said:
Thanks for the lead. Your cryptic reply assumes a lot more competence on
my part then actually exists. I really didn't know how it fit together.

With your hit and another lead from the wonderful Code Project I changed
my existing ...

NameValueCollection nvcQuery = Request.QueryString ;

... to ...

NameValueCollection nvcQuery ;
if ( Context.Request.Form.Count != 0 )
nvcQuery = Request.Form ;
else
nvcQuery = Request.QueryString ;

... and this allows me to call the page using either GET or POST on the
form and process each paramater like ...

nvcQuery["firstname"]

Now I can convert my forms to POST and somewhat hide the values being
passed.

Thanks.

--
-- Thom Little -- www.tlanet.net -- Thom Little Associates, Ltd.
--

Scott M. said:
Since you aren't on a 100% .NET platform, it really doesn't matter which
you sent it with (GET or POST), the Request object can retrieve either
(just has always been the case in classic asp).

Just use:

Request(theFormItemName)
 
I think you meant to say that I could just write ...

Request("firstname") ... and not ... nvcQuery["firstname"]

My aspx program makes three passes through the data in the form to process
the data three different ways.

It is my understanding that Request("firstname") results in a server call
and each reference of this form would also result in a server call.

The approach I reported would be done in one server call.

I think the approach you recommend for a form with 50 fields would result in
150 server calls from my asmx page.

Was I misled?

--
-- Thom Little -- www.tlanet.net -- Thom Little Associates, Ltd.
--

Scott M. said:
You really don't need to go through all of that.

Request.Form(formItemName) will extract data out of the Forms collection
(used when form data is sent via POST)

Request.QueryString(formItemName) will extract data out of the QueryString
collection (used when form data is sent via GET)

Request(formItemName) will extract data from EITHER the Forms or
QueryString collection (regardless of where it is).

So, you don't need to check to see whether the data is in the Forms or
QueryString you can just write: nvcQuery["firstname"]




Thom Little said:
Thanks for the lead. Your cryptic reply assumes a lot more competence on
my part then actually exists. I really didn't know how it fit together.

With your hit and another lead from the wonderful Code Project I changed
my existing ...

NameValueCollection nvcQuery = Request.QueryString ;

... to ...

NameValueCollection nvcQuery ;
if ( Context.Request.Form.Count != 0 )
nvcQuery = Request.Form ;
else
nvcQuery = Request.QueryString ;

... and this allows me to call the page using either GET or POST on the
form and process each paramater like ...

nvcQuery["firstname"]

Now I can convert my forms to POST and somewhat hide the values being
passed.
 
ASPX code is server code. There are no server calls since all the code runs
on the server.

When a form sends its data (using either POST or GET), the data is sent to a
destination (in your case, an .aspx file residing on a server somewhere) and
processing control is handed over to that page. Once that page begins
processing, it doesn't need to make any "server calls" as you put it because
the data has already been sent to the server that is now processing the
code.

In other words, the server that is processing your .aspx code also already
contains the data sent to it from the .htm or .asp form, so there is no
additional overhead related to server calls with looking at the data once,
twice, or 500 times.

There are no performance implications here.


Thom Little said:
I think you meant to say that I could just write ...

Request("firstname") ... and not ... nvcQuery["firstname"]

My aspx program makes three passes through the data in the form to process
the data three different ways.

It is my understanding that Request("firstname") results in a server call
and each reference of this form would also result in a server call.

The approach I reported would be done in one server call.

I think the approach you recommend for a form with 50 fields would result
in 150 server calls from my asmx page.

Was I misled?

--
-- Thom Little -- www.tlanet.net -- Thom Little Associates, Ltd.
--

Scott M. said:
You really don't need to go through all of that.

Request.Form(formItemName) will extract data out of the Forms collection
(used when form data is sent via POST)

Request.QueryString(formItemName) will extract data out of the
QueryString collection (used when form data is sent via GET)

Request(formItemName) will extract data from EITHER the Forms or
QueryString collection (regardless of where it is).

So, you don't need to check to see whether the data is in the Forms or
QueryString you can just write: nvcQuery["firstname"]




Thom Little said:
Thanks for the lead. Your cryptic reply assumes a lot more competence
on my part then actually exists. I really didn't know how it fit
together.

With your hit and another lead from the wonderful Code Project I changed
my existing ...

NameValueCollection nvcQuery = Request.QueryString ;

... to ...

NameValueCollection nvcQuery ;
if ( Context.Request.Form.Count != 0 )
nvcQuery = Request.Form ;
else
nvcQuery = Request.QueryString ;

... and this allows me to call the page using either GET or POST on the
form and process each paramater like ...

nvcQuery["firstname"]

Now I can convert my forms to POST and somewhat hide the values being
passed.
 
It is an excellent improvement. My code actually looks like ...

NameValueCollection nvcQuery = Request ;
String[] astrQuery = nvcQuery.AllKeys ;

.... the alternative ...

String[] astrQuery = Request.AllKeys ;

.... is invalid and if I instead try ...

String[] astrQuery = Request.Params.AllKeys ;

.... I get the form variables (GET or POST) plus the system parameters.

I need to limit it to the form variables.
Is there a better way to just get the form variables?
 
You could use a regular counting loop and just pass the Request object the
counter ( Request(counter) ). This would allow you to work with either
QueryString or Post data, but limits you to just obtaining the form values,
not the names of the form elements that sent the data.

If you want the names and values (which, I suspect you do), you need to use
the Form collection explicitly, as in:

VB.NET

dim item As Object
for each item in request.Form
response.write(item & "=" & request.Form(item))
next





Thom Little said:
It is an excellent improvement. My code actually looks like ...

NameValueCollection nvcQuery = Request ;
String[] astrQuery = nvcQuery.AllKeys ;

... the alternative ...

String[] astrQuery = Request.AllKeys ;

... is invalid and if I instead try ...

String[] astrQuery = Request.Params.AllKeys ;

... I get the form variables (GET or POST) plus the system parameters.

I need to limit it to the form variables.
Is there a better way to just get the form variables?

--
-- Thom Little -- www.tlanet.net -- Thom Little Associates, Ltd.
--

Scott M. said:
ASPX code is server code. There are no server calls since all the code
runs on the server.

When a form sends its data (using either POST or GET), the data is sent
to a destination (in your case, an .aspx file residing on a server
somewhere) and processing control is handed over to that page. Once that
page begins processing, it doesn't need to make any "server calls" as you
put it because the data has already been sent to the server that is now
processing the code.

In other words, the server that is processing your .aspx code also
already contains the data sent to it from the .htm or .asp form, so there
is no additional overhead related to server calls with looking at the
data once, twice, or 500 times.

There are no performance implications here.
 
The counting approach is a good improvement but requires that I know if it
is GET or POST. If I do the following then it is properly limited for
either one.

NameValueCollection nvcRequest ;
if ( Context.Request.Form.Count != 0 )
nvcRequest = Request.Form ;
else
nvcRequest = Request.QueryString ;

foreach ( string strItem in nvcRequest )
{
}
 
Yes, but what is your point exactly? What are you dealing with and what are
your needs? If you tell us, we can give you the quickest solution.
 
You did. You were very helpful. The optimal solution is now deployed.

The requirement was to have a single .ASPX page process either GET or POST
input.

The capability was a fairly large number of deployed .ASP and .HTML websites
that call a generalized form handling page written in ASP.NET 1.1. They all
use GET.

Because of e-mail address harvesting craze I have been removing all direct
e-mail references in my websites. I was also wanting to hide the parameters
from the query string.

If I had an .ASPX page that would process either GET or POST then I cold use
it immediately for all existing deployed websites (using GET) and use POST
in the future for new and revised websites.

This is where the requirement to process either or POST in the same .ASPX
page came from.

This page now exists and is enhanced by the suggestions that you made.

Thank you.
 
Back
Top