Diferença entre pedido.Forma e pedido.QueryString?

alguns podem dizer-me a diferença exacta entre Request.Form e Request.QueryString?

Eu sei uma diferença, Tipo

Se o método de pedido HTTP for POST, os dados apresentados pelo utilizador estão no Pedido.Form () collection

Se o método de requisição HTTP for GET, então os dados enviados pelo usuário estão na Pedido.QueryString () Colecção

Mais alguma diferença? e qualquer exemplo seria muito apreciado.

Author: Ramesh Rajendran, 2013-12-20

6 answers

Em Request.Form os dados são postados no cabeçalho http enquanto que em QueryString os dados são enviados através do url.

 19
Author: Adil, 2013-12-20 06:04:30

Encontrei outra diferença

Request("id") 

Primeiro vai tentar localizar

Request.Form("id") 

Depois

Request.Querystring("id") 

Depois

Request.Cookies("id") 

E finalmente

Request.ServerVariables("id") 

Recomenda-se a utilização da Convenção explícita de designação, se possível, porque é mais eficiente e mais readable.it também permite que você tenha certeza de onde suas informações estão vindo, uma vez que o sistema vai parar após o primeiro hit é feito.... Também é mais rápido para o sistema se você especificar a localização de informacao.

E podemos consultar este link para mais alguns detalhes:

Http://www.hanselman.com/blog/ASPNETParamsCollectionVsQueryStringFormsVsRequestindexAndDoubleDecoding.aspx

Mas qualquer um sabe qualquer outra diferença, agradeço muito .
 12
Author: Ramesh Rajendran, 2013-12-20 06:17:57

Como indicado em MSDN,

(pedido.Formulário : o valor do pedido.Form (element) é um array de todos os valores do elemento que ocorrem no corpo do pedido. Podes. determinar o número de valores de um parâmetro por chamada Pedido.Forma (elemento).Contar. Se um parâmetro não tiver múltiplos valores associados a ele, a contagem é 1. Se o parâmetro não for encontrado, a contagem é 0.

E (Pedido.QueryString : o valor de Pedido.QueryString (parâmetro) é uma matriz de todos os valores de parâmetro que ocorrem em QUERY_STRING. Você pode determinar o número de valores de um parâmetro por pedido de chamada.QueryString (parâmetro).Contar. Se uma variável não tem vários conjuntos de dados associados a ele, a contagem é 1. Se a a variável não é encontrada, a contagem é 0.

Então, algumas coisas a notar:

De uma forma típica numa página, podemos incluir alguns elementos escondidos:

<form method="post">
   <input type="hidden" name="lol" value="cat" />
   <input type="text" />
</form>

Escondido elementos( se a memória não servir), não são mostrados no QueryString. Então, eu assumiria que há algumas coisas que não são mostradas em Request.QueryString. Infelizmente eu estou no processo de reinstalação de aplicativos dev em uma nova máquina e não posso testar isso no momento, mas se eu estiver certo, quando você POST um formulário, mais detalhes sobre o formulário e seu conteúdo é enviado. E quando você acessar QueryString, você só está vendo as coisas que compõem a totalidade da URL, por exemplo:

Http://somesite.com/index.html?v=1&NonHiddenElement=lol&ManualValue=hello

 7
Author: uSeRnAmEhAhAhAhAhA, 2013-12-20 06:24:55

Pedido.Form - significa que você está querendo recuperar os valores para o formulário que foi publicado.

Pedido.QueryString {[[3]} - significa que você está querendo recuperar valores que foram passados no querystring.

 3
Author: vikky, 2013-12-20 06:07:31
Pedido.Formulário ()
  • a colecção de formulários recupera os valores dos elementos de formulários publicados no corpo do pedido HTTP, apenas os elementos e valores que existem na sua forma.
Pedido.QueryString ()
  • a colecção QueryString recupera os valores das variáveis no texto da consulta HTTP; aqui poderá adicionar qualquer uma das suas variáveis personalizadas e o valor que a dose de evento não existe na sua forma.
 2
Author: H. Mahida, 2013-12-20 06:33:45

Pedido.Colecção De Formulários

The Form collection retrieves the values of form elements posted to the HTTP request body, with a form using the POST method.
Form input is contained in headers. It is wise to not trust the data that is contained in headers, as this information can be falsified by malicious users. For example, do not rely on data such as cookies to securely identify a user.
As a security precaution, always encode header data or user input before using it. A general method of encoding data is to use Server.HTMLEncode. Alternatively, you can validate header data and user input with a short function such as the one described in Validating User Input to Avoid Attacks. For more detailed information about developing secure Web applications, see chapter 12 of MS Press - Writing Secure Code.
Syntax
Request.Form(element)[(index)|.Count]
Parameters
element
The name of the form element from which the collection is to retrieve values.
index
An optional parameter that enables you to access one of multiple values for a parameter. It can be any integer in the range 1 to Request.Form(parameter).Count.
Applies To
Request Object
Remarks
The Form collection is indexed by the names of the parameters in the request body. The value of Request.Form(element) is an array of all the values of element that occur in the request body. You can determine the number of values of a parameter by calling Request.Form(element).Count. If a parameter does not have multiple values associated with it, the count is 1. If the parameter is not found, the count is 0.
To reference a single value of a form element that has multiple values, you must specify a value for the index parameter. The index parameter may be any number between 1 and Request.Form(element).Count. If you reference one of multiple form parameters without specifying a value for index, the data is returned as a comma-delimited string.
When you use parameters with Request.Form, the Web server parses the HTTP request body and returns the specified data. If your application requires unparsed data from the form, you can access it by calling Request.Form without any parameters.

Pedido.Colecção De QueryString

The QueryString collection retrieves the values of the variables in the HTTP query string. The HTTP query string is specified by the values following the question mark (?). Several different processes can generate a query string. For example, the following anchor tag generates a variable named string with the value "this is a sample."
<A HREF="example.asp?string=this is a sample">string sample</A>

Query strings are also generated by sending a form or by a user typing a query into the address box of the browser.
Query strings are contained in request headers. It is wise to not trust the data that is contained in headers, as this information can be falsified by malicious users. For example, do not rely on data such as cookies to securely identify a user.
As a security precaution, always encode header data or user input before using it. A general method of encoding data is to use Server.HTMLEncode. Alternatively, you can validate header data and user input with a short function such as the one described in Validating User Input to Avoid Attacks. For more detailed information about developing secure Web applications, see chapter 12 of MS Press - Writing Secure Code.
Syntax
Request.QueryString(variable)[(index)|.Count]
Parameters
variable
Specifies the name of the variable in the HTTP query string to retrieve.
index
An optional parameter that enables you to retrieve one of multiple values for variable. It can be any integer value in the range 1 to Request.QueryString(variable).Count.
Applies To
Request Object
Remarks
The QueryString collection is a parsed version of the QUERY_STRING variable in the ServerVariables collection. It enables you to retrieve the QUERY_STRING variable by name. The value of Request.QueryString(parameter) is an array of all of the values of parameter that occur in QUERY_STRING. You can determine the number of values of a parameter by calling Request.QueryString(parameter).Count. If a variable does not have multiple data sets associated with it, the count is 1. If the variable is not found, the count is 0.
To reference a QueryString variable in one of multiple data sets, you specify a value for index. The index parameter can be any value between 1 and Request.QueryString(variable).Count. If you reference one of multiple QueryString variables without specifying a value for index, the data is returned as a comma-delimited string.
When you use parameters with Request.QueryString, the server parses the parameters sent to the request and returns the specified data. If your application requires unparsed QueryString data, you can retrieve it by calling Request.QueryString without any parameters.
You can use an iterator to loop through all the data values in a query string.

Por exemplo, se for enviado o seguinte pedido:

Para mais detalhes clique neste link

 -1
Author: Lijo, 2013-12-20 06:11:59