HTTP encoding problem

https://blog.csdn.net/qq_38409944/article/details/80637980

https://blog.csdn.net/a83370892/article/details/82726700?depth_1-utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromBaidu-2&utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromBaidu-2

ISO-8859-1 can be used as a transit station, but gbk can not be  https://blog.csdn.net/qq_38409944/article/details/80637345

http://www.ruanyifeng.com/blog/2010/02/url_encoding.html

 

request:

Conclusion 1: The encoding of the URL path uses UTF-8 encoding.

Conclusion 2: The encoding of the query string uses the default encoding of the operating system.

The above two conclusions are obtained by directly entering the URL in the browser

 

The above is the case of directly entering the URL

(That is, before this time the server did not give a response (1, <meta http-equiv = "Content-Type" content = "text / html; charset = xxxx">

 2、response.setContent())

But the more common situation is that on the opened web page (this time the server has responded, may set content-type, 1, set in html, 2, set in response.setContent) , use Get or The Post method makes an HTTP request.

 

--------------------------------------------

On an open webpage

According to the experiment of teacher Lu Ruilin of ZTE University in Taiwan , the encoding method at this time is determined by the encoding of the web page, that is, the setting of the character set in the HTML source code ().

  <meta http-equiv="Content-Type" content="text/html;charset=xxxx">

If the last charset in this line is UTF-8, the URL is encoded in UTF-8; if it is GB2312, the URL is encoded in GB2312.

 

Conclusion 3 is that the encoding of the GET and POST methods uses the encoding of the web page.

--------------------------------------------

 

In Ajax calls, IE always uses GB2312 encoding (the operating system's default encoding), while Firefox always uses utf-8 encoding. This is our conclusion 4.

 

--------------------------------------------

Assuming that you have understood before, then you should feel a headache at this time. Because it is too confusing. Different operating systems, different browsers, and different web page character sets will result in completely different encoding results. Would it be too scary if the programmer wants to take every result into account? Is there a way to ensure that the client sends a request to the server using only one encoding method?

The answer is yes, use Javascript to encode the URL first, and then submit it to the server, don't give the browser the opportunity to intervene (because after encoding, the URL's character composition meets the rules, it will not be encoded).

Because the output of Javascript is always consistent, it ensures that the data obtained by the server is in a uniform format.

 

--------------------------------------------

 

encodeURI () is the function used to encode URL in Javascript.

It focuses on encoding the entire URL, so in addition to common symbols, other symbols that have special meaning in the URL "; /?: @ & = + $, #" Are not encoded.

After encoding, it outputs the UTF-8 form of the symbol, and adds% before each byte.

 

 

 

==========================================

iso can do transit, so it can

String userName = new String(request.getParamter("userName").getBytes("ISO8859-1"),"utf-8")

If it is changed to gbk, even number of characters can be used as a transit, while odd number of characters cannot be used for transit  https://blog.csdn.net/qq_38409944/article/details/80637345

 

Guess you like

Origin www.cnblogs.com/sheajin/p/12690380.html