当前位置:网站首页>URLEncoder. Encode and urldecoder Decode processing URL
URLEncoder. Encode and urldecoder Decode processing URL
2022-07-03 22:42:00 【╱℡&▓】
URLEncoder.encode (str,"UTF-8");
URLDecoder.decode(str,"UTF-8");
URLEncoder.encode and URLDecoder.decode Handle url Special parameters of
In the use of url Of queryString When passing parameters , Because the value of the parameter , By DES Encrypted , And the result of encryption is Base64 Encoding string of , Be similar to :
za4T8MHB/6mhmYgXB7IntyyOUL7Cl++0jv5rFxAIFVji8GDrcf+k8g==
obviously It contains Special characters : / + = wait , If you go straight through url To pass this parameter :
url = "xxxxx?param=" + "za4T8MHB/6mhmYgXB7IntyyOUL7Cl++0jv5rFxAIFVji8GDrcf+k8g==";
Then get at the server param It will become a value similar to the following :
"za4T8MHB/6mhmYgXB7IntyyOUL7Cl 0jv5rFxAIFVji8GDrcf k8g=="
We see Three + No. 1 disappeared .
And the reason is : If url When the parameter value contains special characters , Need to use url code .
url = "xxxxx?param=" + URLEncoder.encode("xxx", "utf-8");
Then when the server obtains :
String param = URLDecoder.decode(param, "utf-8");
In this way, the correct value can be obtained :"za4T8MHB/6mhmYgXB7IntyyOUL7Cl++0jv5rFxAIFVji8GDrcf+k8g=="
Actually js There are functions with similar functions in :
See :js Three encoding functions in :escape,encodeURI,encodeURIComponent
matters needing attention :
URLEncoder should be the way to go. You only need to keep in mind to encode only the individual query string parameter name and/or value, not the entire URL, for sure not the query string parameter separator character &
nor the parameter name-value separator character =
String q = "random word Close up 500 bank $";
String url = "http://example.com/query?q=" + URLEncoder.encode(q, "UTF-8");
URLEncoder must only code Parameters Or the value of the parameter , Cannot encode the whole url, Nor can we do it together param=value Encoding . It should be : param=URLEncode(value, "utf-8")
perhaps URLEncode(param, "utf-8")=URLEncode(value, "utf-8")
because url Medium & and = They are used as parameters between as well as Separator between parameter and value . If we code together , You can't distinguish them .
Further reference documentation :
https://www.talisman.org/~erlkonig/misc/lunatech%5Ewhat-every-webdev-must-know-about-url-encoding/
边栏推荐
- Exclusive download! Alibaba cloud native brings 10 + technical experts to bring "new possibilities of cloud native and cloud future"
- [template summary] - binary search tree BST - Basics
- [sg function]split game (2020 Jiangxi university student programming competition)
- Harbor integrated LDAP authentication
- Programming language (1)
- LeetCode 1646. Get the maximum value in the generated array
- Leetcode week 4: maximum sum of arrays (shape pressing DP bit operation)
- What are the common computer problems and solutions
- User login function: simple but difficult
- 2 spark environment setup local
猜你喜欢
On my first day at work, this API timeout optimization put me down!
Cesium terrain clipping draw polygon clipping
What indicators should be paid attention to in current limit monitoring?
Buuctf, misc: n solutions
How to connect a laptop to a projector
Es6~es12 knowledge sorting and summary
Blue Bridge Cup -- Mason prime
How to switch between dual graphics cards of notebook computer
string
MLX90614 driver, function introduction and PEC verification
随机推荐
[actual combat record] record the whole process of the server being attacked (redis vulnerability)
BUUCTF,Misc:LSB
Label coco format data and format data in the upper left corner and lower right corner are mutually converted
Summary of basic knowledge of exception handling
Pointer concept & character pointer & pointer array yyds dry inventory
Data consistency between redis and database
Common problems in multi-threaded learning (I) ArrayList under high concurrency and weird hasmap under concurrency
How can enterprises and developers take advantage of the explosion of cloud native landing?
Blue Bridge Cup Guoxin Changtian MCU -- program download (III)
What indicators should be paid attention to in current limit monitoring?
Text replacement demo
Conditional statements of shell programming
Take you to master the formatter of visual studio code
6.0 kernel driver character driver
LeetCode 1646. Get the maximum value in the generated array
Hcip day 16 notes
Uboot migration
股票炒股开户注册安全靠谱吗?有没有风险的?
How to obtain opensea data through opensea JS
33 restrict the input of qlineedit control (verifier)