[2019] recording a problem: get the back end of the URL parameter values within plus sign "+" into space ""

Problem: URL parameters plus sign "+" into space ""

A phenomenon

     URL如:http://example.****.com/controller/action?param=rice+cook+panda

  The rear end through Request.QueryString [ "param"] ways to gain value, the value in the plus "+" will be converted to space ""

  E.g. transmission "rice + cook + panda", will take the "rice cook panda"

Second, the cause

  W3C standards, when the Content-Type is application / x-www-form-urlencoded, URL query parameter name and value spaces use a plus sign + substitution, so almost all use the standard browser filed after the form, URL query parameter space will be compiled into a plus sign +.

  In another specification RFC2396, define the URI, the URI reserved characters are to be escaped as% HH format (Section 3.4 Query Component), and therefore spaces are encoded as 20%, plus + themselves and as a reserved word was compiled% 2B, follow the RFC 2396 standard for certain applications, it may not accept a + sign appears in the query string, that it is illegal characters.

  Therefore, a security initiative is the URL unified% 20 to encode the space character.

Third, ideas and methods to solve

  Understand the causes, treatment for reasons to do to solve this situation.

       Roadmap: the + sign to replace the URL% 2B

       Processed URL should be: http: //example.****.com/controller/action param = rice% 2Bcook% 2Bpanda?

       1, the transmitting side approach

  Different programming languages ​​to solve such problems method, much the same, the ultimate goal is the plus sign in the parameter "+" replaced% 2B:

        Java Solution (recommended)

 URLEncoder.encode("rice+cook+panda","UTF-8"); 

        C # solution (recommended)

 HttpUtility.UrlEncode("rice+cook+panda"); 

 Server.UrlEncode("rice+cook+panda") 

        JS solution (recommended)

 encodeURIComponent("rice+cook+panda") 

General Method stupid (not recommended): + The numbers in the function parameters were replaced repace% 2B

        2, the receiving side approach

       This problem occurs because the transmit side, it is not recommended at the receiving end of special treatment.

  In special cases (for temporary emergency only parameters of a single URL): treatment receiving end, forces the spaces within the acquired parameter becomes plus "" Replace method by "" is replaced by the + symbol (not recommended, this is pit)

Fourth, expand the extension problem

  The question is mainly of a special symbol in the URL parameters leads to a special treatment, such a situation + number, other special symbols NATURAL similar situation exists such as: / = the like.

  It is therefore recommended the use of a variety of internal programming language processing function url to solve such problems, we do not recommend a way to find a replacement, but the receiving end do not recommend special treatment.

Guess you like

Origin www.cnblogs.com/littlemo/p/10968050.html
Recommended