巴扎黑2017-04-18 10:37:18
It’s not just a matter of post
编码,而是characterEncoding
只对body
有效。
http有很多method
比如像put
方法也是有body
的。
即使你使用post
如果url
中存在中文query parameters
一样需要针对url
setting the encoding.
PHP中文网2017-04-18 10:37:18
1. Because few people use the GET method to transmit Chinese content. As for why the filter only solves the problem of Chinese transmission garbled characters in the POST method, I think it is not a technical problem. It may be intentional by the designer, hoping to guide us to use the POST method more. It's like requiring a large truck to carry a lot of people like a passenger car. For the person who designs the large truck, he won't take this situation into consideration.
2. The problem of transmitting Chinese garbled characters in the GET method is not unsolvable. The solution is also very simple, but it is not recommended because this method is not universal for the POST method. The sample code is as follows:
String username = request.getParameter("username");
username = new String(username.getBytes( "iso-8859-1" ), "utf-8");