当前位置:网站首页>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/
边栏推荐
- Take you to master the formatter of visual studio code
- Data consistency between redis and database
- Common problems in multi-threaded learning (I) ArrayList under high concurrency and weird hasmap under concurrency
- Firefox set up proxy server
- Covariance
- 2022 safety officer-b certificate examination summary and safety officer-b certificate simulation test questions
- Exclusive download! Alibaba cloud native brings 10 + technical experts to bring "new possibilities of cloud native and cloud future"
- pycuda._ driver. LogicError: explicit_ context_ dependent failed: invalid device context - no currently
- Oil monkey plug-in
- Creation of the template of the password management software keepassdx
猜你喜欢
![Yyds dry goods inventory [practical] simply encapsulate JS cycle with FP idea~](/img/af/1975b37d81bbdb9709ff181b9a72f9.jpg)
Yyds dry goods inventory [practical] simply encapsulate JS cycle with FP idea~

Leetcode week 4: maximum sum of arrays (shape pressing DP bit operation)

Redis single thread and multi thread

Blue Bridge Cup Guoxin Changtian single chip microcomputer -- software environment (II)

2 spark environment setup local

Blue Bridge Cup -- guess age

Mysql database - Advanced SQL statement (I)

The reason why the computer runs slowly and how to solve it

Teach you how to run two or more MySQL databases at the same time in one system
Creation of the template of the password management software keepassdx
随机推荐
540. Single element in ordered array
Codeforces Round #768 (Div. 1)(A-C)
To rotate 90 degrees clockwise and modify the video format
Bluebridge cup Guoxin Changtian single chip microcomputer -- detailed explanation of schematic diagram (IV)
SDMU OJ#P19. Stock trading
Comparable interface and comparator interface
LeetCode 540. A single element in an ordered array
C3p0 connection MySQL 8.0.11 configuration problem
Blue Bridge Cup Guoxin Changtian single chip microcomputer -- software environment (II)
Overview of Yunxi database executor
Bluebridge cup Guoxin Changtian single chip microcomputer -- hardware environment (I)
[untitled]
IPhone development swift foundation 09 assets
Errors taken 1 Position1 argument but 2 were given in Mockingbird
Hcip day 14 notes
Druids connect to mysql8.0.11
Go error collection | talk about the difference between the value type and pointer type of the method receiver
Opengauss database log management guide
. Net ADO splicing SQL statement with parameters
Leetcode: a single element in an ordered array