Control character in cookie value or attribute exception, or An invalid character [34] was present in the cookie value exception, etc. So how to solve such a problem, let’s follow the code step by step to look at
in our store String value or a json String to the cookies first pass validateCookieValue this method, as shown below
private void validateCookieValue(String value) {
int start = 0;
int end = value.length();
if (end > 1 && value.charAt(0) == '"' && value.charAt(end - 1) == '"') {
start = 1;
end--;
}
char[] chars = value.toCharArray();
for (int i = start; i < end; i++) {
char c = chars[i];
if (c < 0x21 || c == 0x22 || c == 0x2c || c == 0x3b || c == 0x5c || c == 0x7f) {
throw new IllegalArgumentException(sm.getString(
"rfc6265CookieProcessor.invalidCharInValue", Integer.toString(c)));
}
}
}
we take a look at this way, when do array with value value to each of these characters is verified, which, according to the theory of the if statement is an exception is thrown directly, so there will be a we Control character in the cookie value or attribute. Among them, 0x21 and 0x22 are hexadecimal representation numbers, and the corresponding positions are 33 and 34 respectively;
First of all, do cookies contain ASCII encoding?Then we use GBK or UTF-8 encoding when we use parsing. When it comes to ASCII code 0X21 and 0X22, what is the corresponding character?We need to check the ASCII code comparison table. OK, let’s look at the corresponding ASCII table
In , the two marked in red are randomly specified. I believe you will know why you reported that exception after reading the picture you bought.
br>>
lencoder. Encode (name, “UTF-8 “)
Urlencoder. Encode (name,” UTF-8 “)
Urlencoder.
URLDecoder.decode(cookies[i].getName(),”utf-8″)
Read More:
- Illegalargumentexception error when adding cookie to response
- Illegalargumentexception: control character in cookie value or attribute tomcat7
- Three ways of adding cookie by scratch
- How to Fix char cannot be dereferenced Error
- What are the web front end technologies? What are the differences between cookie and session
- Some uncommon problems and solutions of cookie
- Split keyword in ABAP when the separator is at the beginning and end of the string
- error: unclosed character literal (How to Fix)
- 43. Implementation of the shortest code of multiply strings | Java
- R reads JSON data
- [Warning] incompatible implicit declaration of built-in function ‘strcat’
- Unicode encodeerror: ‘GBK’ codec can’t encode character solution
- Java compareto() method
- Java prompt unmappable character for encoding solution
- Python’s json.loads Invalid control character
- Java.lang.Character . isdigit() and isletter() methods
- Perfectly solve the 1366 error of saving Chinese in MySQL
- Error c2137 of C language: empty character constant (Fixed)
- json.load (file) error
- Difference between isempty method and isblank method in stringutils