当前位置:网站首页>Additional: [urlencoder.encode (string to be encoded, "encoding method");] (what is it?; why do we use this to encode when we set values in cookies?) (to be improved...)
Additional: [urlencoder.encode (string to be encoded, "encoding method");] (what is it?; why do we use this to encode when we set values in cookies?) (to be improved...)
2022-07-27 13:24:00 【Small withered forest】
explain :
(1) Why did you write this blog ?: stay 【51: The fifth chapter : Development admin management service :4: Development 【 newly added admin account number , Interface 】;】 when , Find out :
● When the administrator logs in , We put the administrator's atoken、aid、aname Set in cookie; then , In the setting, enter cookie When , Will use 【URLEncoder.encode( String to be encoded , " Encoding mode ");】 Transcoding ;
● however , We're setting up aname When , If aname If there is Chinese in it , It will turn Chinese into " The statement "(PS: In fact, it's garbled here , It's not reasonable to );
● then , Facing the above situation , My first thought is : We ask cookie When setting the value in , If you encounter " String containing Chinese ", We don't use 【URLEncoder.encode( String to be encoded , " Encoding mode ");】 Set the encoding method ;;; however , And worry about doing so , It may lead to other unpredictable consequences ;
(2) therefore , This blog mainly solves the following problems :
● problem 1:【URLEncoder.encode( String to be encoded , " Encoding mode ");】 What is it , What does it do ;
● problem 2: be nice with yourself , We set up cookie When , Why do I have to use 【URLEncoder.encode( String to be encoded , " Encoding mode ");】 Set the encoding method ?
(3) The articles referenced in this blog are :
●【 Why urlencode()】, The author of this article is 【yanlei】;
●【 Do you really understand URLEncode Do you ?】, The author of this article is 【xiaxveliang】;
Catalog
1. Reference article 1: Why URLEncoder?
2. Reference article 2: Do you really understand URLEncode Do you ?
(1) I have encountered many places that need to set the coding method before : For example, the garbled code in the request , Garbled code in response ,HTML And the garbled code in the front-end static file , When the front and back end interact JSON The mess of ,Tomcat The mess of , The coding method of the compiler, and so on ; These problems , Want to solve , There are clear solutions , There's nothing to repeat ;
(2) then , What we meet here is URLEncoder.encode();
One : problem 1:【URLEncoder.encode( String to be encoded , " Encoding mode ");】 What is it , What does it do ;
1. Reference article 1: Why URLEncoder?
Reference from 【 Why urlencode()】, The author of this article is 【yanlei】;
……………………………………………………
Through the measured ,【URLEncoder.encode( String to be encoded , " Encoding mode ");】 It has this effect ;
……………………………………………………
namely , Through the description here , There seems to be such a feeling :
● sometimes , We will hope to pass url, To pass some data ;
● and ,url There are restrictions on the data format , For example, there should be no spaces 、 Cannot share @ character , No Chinese characters ;
● therefore ,【 If we have some characters , Want to attach to url in , To pass on 】+【 Among these characters , The space 、@ character 、 Or Chinese 】 When , You need to check this character first , utilize 【URLEncoder.encode( String to be encoded , " Encoding mode ");】 De coding , To conform to url The format of ;
● then , When coding , It doesn't matter what encoding method is used ; As long as both parties agree ;
2. Reference article 2: Do you really understand URLEncode Do you ?
Reference from 【 Do you really understand URLEncode Do you ?】, The author of this article is 【xiaxveliang】;
……………………………………………………
● The above case , It's easy to understand ;
● of Content-Type The content of , You can refer to 【Servlet And JSP Advanced three : In the response header Content-Type】、【Content-Type Detailed explanation 】 And so on ;
thus , I feel that the above is for 【URLEncoder.encode( String to be encoded , " Encoding mode ");】 Introduction to , For the moment , Just " Enough " 了 ; temporary , There is no need to delve too deeply ;
Two : problem 2: be nice with yourself , We set up cookie When , Why do I have to use 【URLEncoder.encode( String to be encoded , " Encoding mode ");】 Set the encoding method ?
1. problem ;
As in 【51: The fifth chapter : Development admin management service :4: Development 【 newly added admin account number , Interface 】;】 in , As mentioned ; be nice with yourself , We set up cookie When , Why do I have to use 【URLEncoder.encode( String to be encoded , " Encoding mode ");】 Set the encoding method ?
2. analysis ;
(1) In limine , We set it into cookie Yes. uid and utoken; You can refer to 【27: The third chapter : Developing a pass service :10:【 register / Sign in 】 Interface : register / Sign in OK after , Send the user session information (uid,utoken) Save to redis and cookie in ;( A major point : Set up cookie)】;
(2) at that time ,uid( Generated by snowflake Algorithm ) and utoken( utilize UUID Generated ) There are no special characters 、 Space 、@ 、 Chinese, etc ; therefore , Its course 【URLEncoder.encode( String to be encoded , " Encoding mode ");】 After transcoding , It is constant ;
(3) then , We put uid and utoken Set to cookie In the after , Later, judge whether the user logs in 、 publish || Delete articles 、 When querying the article list and other interfaces , The front end will start from cookie In order to get uid and utoken, Set it into header Request header ; meanwhile , You see uid Set in url in ;
(4) therefore , Blind guess here is the consideration : Since it is set into cookie Value , The front end may be brought over and put url in ; that , We ask cookie When setting the value in , Simply use it all 【URLEncoder.encode( String to be encoded , " Encoding mode ");】 Code it ;
(5) however , The one size fits all approach above , It came into being. 【51: The fifth chapter : Development admin management service :4: Development 【 newly added admin account number , Interface 】;】 Meet in , problem ;
3. Solutions ;
There is already a solution in my heart ; however , Because I'm not sure which solution test is more appropriate , Which solution is more adopted by everyone in actual development ; therefore , Put it on hold for a while ……
For the moment , Keep the status quo first .
边栏推荐
- Poj1273 drainage ditches [maximum flow] [SAP]
- leetcode——83,24;机器学习——神经网络
- SQL group by statement
- 18. Text processing tool -grep
- 最新版泛域名证书申请
- 纵横靶场-图片的奥秘
- feign的动态代理
- 高度塌陷最终解决方案(无副作用)
- 粘制定位
- Write a program, accept a string consisting of letters, numbers and spaces, and a character, and then output the number of characters in the input string. Case insensitive.
猜你喜欢

力扣 1480. 一维数组的动态和 383. 赎金信412. Fizz Buzz

字节跳动的 Flink OLAP 作业调度和查询执行优化实践

What should I do if I can't see any tiles on SAP Fiori launchpad?

Xposed+fdex2 app shelling (black cat complains about app shelling)

接口测试实战教程01:接口测试环境搭建

v-show

Is it easy to find a job after programmer training and learning

Redis summary: cache avalanche, cache breakdown, cache penetration and cache preheating, cache degradation
![[cute new solution] Fibonacci sequence](/img/2d/64cdc8b7625ee7a81275ad25dc2b7a.png)
[cute new solution] Fibonacci sequence

责任链模式在转转精准估价中的应用
随机推荐
Have you understood these 30 questions of enabling financial risk control plus points
文本样式
Text style
SQL statement problem, calculate the data with a difference of less than 10 minutes to be displayed as the same batch of data
v-text
能说一说 Kotlin 中 lateinit 和 lazy 的区别吗?
51:第五章:开发admin管理服务:4:开发【新增admin账号,接口】;(只开发了【用户名+密码的,方式】;【@T…】注解控制事务;设置cookie时,是否需要使用URLEncoder去编码;)
Seata 在蚂蚁国际银行业务的落地实践
pg同步多张数据表至mysql 有办法简化配置吗?
feign的动态代理
Application for the latest version of Pan domain name certificate
PAT乙级 1109 擅长C(详解)
银行案例|Zabbix跨版本升级指南,4.2-6.0不香吗?
SQL group by statement
xshell7可以登录mysql虚拟机不能登陆mysql
Redis summary: cache avalanche, cache breakdown, cache penetration and cache preheating, cache degradation
Fixed positioning
How can the top 500 enterprises improve their R & D efficiency? Let's see what industry experts say!
2022年7月24日 暑假第二周训练
纵横靶场-图片的奥秘




















