当前位置:网站首页>Get and post requests
Get and post requests
2022-04-21 11:23:00 【Carbon water carbon water】
GET And POST request
Common situation
GET
- form label method=get
- a label
- link Tags introduced css
- Script Tags introduced js file
- img The tag introduces the picture
- iframe introduce html page
- Enter the address in the browser address bar and press enter
POST
- form label method=pos
difference
| Comparative study | Get | post |
|---|---|---|
| The parameter appears in URL in | yes | no |
| Length limit | Yes | nothing |
| Security | low | high |
| URL Can spread | yes | no |
| Upload files | I won't support it | Support |
The code problem
Tips
- tomcat The default character encoding used in :iso-8859-1, No Chinese support
- Common coding methods that support Chinese
| Encoding mode | Included characters |
|---|---|
| gb2312 | Commonly used simplified Chinese characters |
| gbk | Simplified and traditional Chinese characters |
| utf-8 | Characters required by all countries |
Problem analysis
Reference article :
Tomcat Of URIEncoding、useBodyEncodingForURI and CharacterEncodingFilter
from StringHttpMessageConverter Analysis of the garbled code process between the client and server
URL The problem of Chinese character coding and the solution of garbled code
URIEncoding and UseBodyEncodingForURI The explanation of
Post,Get Reason and solution of request garbled code


- When we enter parameters in the form, we jump , The address bar will show
http://localhost:8080/test?userName= Zhang San &userPwd=1&rePwd=1&bd= cell-phone number, If you copy the address and paste , The content ishttp://localhost:8080/day0321/login/doLogin.jsp?userName=%E5%BC%A0%E4%B8%89&userPwd=1&rePwd=1&bd=%E6%89%8B%E6%9C%BA%E5%8F%B7, This is the encoded address , What kind of coding method is called URL code
(chrome The browser always starts with UTF-8 Convert China into a byte array ) - When a browser sends a request , The server is requested content-type To parse the request data , When the browser request does not specify content-type when ,Tomcat The server defaults to ISO-8859-1
- Because the two coding methods are different , So there is garbled code
resolvent
- Set the encoding of requests and responses ( Apply to post)
// The call is valid until the request parameter is obtained.
request.setCharacterEncoding("utf-8");// Set the encoding of the request
response.setCharacterEncoding("utf-8");// commonly page It has been set up utf-8 了 , This sentence can be omitted
<%@ page language="java" contentType="text/html; charset=utf-8"%>
-
get The request is garbled
① Cure the symptoms :new String( s.getBytes("iso-8859-1"), "utf-8" );
② Permanent cure : To configure tomcat\conf\server.xml file
URIEncoding="UTF-8": Unified settings are used for decoding URL Character encoding of ( Including address and parameters ), The default value is ISO-8859-1
useBodyEncodingForURI="true": Whether to use request.setCharacterEncoding The set code has no effect on the request parameters ( Do not include address ) decode , Default false, It is mainly used for Tomcat4.1.x in .

Why? post And get The solutions of the two submission methods are different
POST
① The coding is determined by the page , namely ContentType(“text/html; charset=utf-8”)
② When the form is submitted , The browser will start with ContentType Encode the parameters in the encoding format , Then submit it to the server .
③ It is also used on the server side ContentType To decode
GET
① GET The submission method will attach parameters to the address , Therefore, the coding of parameters is by URL It depends on the code
② page Medium ContentType And request.setCharacterEncoding The method is not correct HTTP Decode the content of the header
③ therefore GET Method still uses the default ISO-8859-1 decode
④ If you want to decode correctly, you must set URIEncoding perhaps Set the request.setCharacterEncoding To set up useBodyEncodingForURI
版权声明
本文为[Carbon water carbon water]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204211122218133.html
边栏推荐
- 塔米狗知识|股权转让合法程序有哪些?
- redis面试问题
- Kubernetes 中数据包的生命周期 -- 第 1 部分
- Matlab GUI --- subject selection (animation demonstration)
- 把數組字典寫入csv格式
- 注册新西兰公司流程和需要的资料
- Simple threading - using threads to run multiple browsers easily
- Introduction to Alibaba's super large-scale Flink cluster operation and maintenance system
- 10000 yuan gift pool play "Lighthouse" prize essay attack
- 如何快速搭建一个像叮咚买菜这样的APP?
猜你喜欢
随机推荐
Simple threading - using threads to run multiple browsers easily
Écrire un dictionnaire de tableaux au format CSV
MATLAB---选择省份城市应用
Introduction to Alibaba's super large-scale Flink cluster operation and maintenance system
实现浏览器多标签页通信
Matlab GUI --- subject selection (animation demonstration)
Unix哲学与高并发
Spark快速入门系列(5) | Spark环境搭建—standalone(2) 配置历史日志服务器
EL表达式
Suffix array special training
注册新西兰公司流程和需要的资料
JSTL -- JSP 标准标签库
[nonlinear control theory] 1_ Lyapunov direct method
从思维转变看数字化转型 IT 经营
Kubernetes 中数据包的生命周期 -- 第 1 部分
package.json
Realize browser multi tab communication
【面试普通人VS高手系列】b树和b+树的理解
程序员如何确保软件没 Bug?
Special training of AC automata








![[二叉数]对称二叉树](/img/15/a1285ae7f31dd2e9f7b00350b1fdc6.png)