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:
- Storing JSON data in session storage
- Illegalargumentexception: control character in cookie value or attribute tomcat7
- The solution of “double quotation marks become escape characters” in Java parsing JSON
- [development experience] solution to unexpected syntax error: unexpected identifier in JSON parsing
- Parsing double quotation marks with JSON
- How to query the production environment logstash report error parsing JSON
- Err: error parsing query: found name, expected identifier, string
- Gson Parsing exceptions: Use JsonReader.setLenient(true) to accept malformed JSON at line 1 column 1 path $
- npm ERR! registry error parsing json error report solution
- Illegalargumentexception error when adding cookie to response
- 【ipfs-api】npm ERR! JSON.parse package.json must be actual JSON, not just JavaScript.
- Three ways of adding cookie by scratch
- A repeated string is composed of two identical strings. For example, abcabc is a repeated string with length of 6, while abcba does not have a duplicate string. Given any string, please help Xiaoqiang find the longest repeated substring.
- User defined profile in vscode settings.json And default configuration defaultSettings.json
- Some uncommon problems and solutions of cookie
- [jQuery] jQuery operates on JSON strings or JSON objects
- java.lang.NoSuchMethodError: org.json.JSONObject.put(Java/lang/String; Java/util/Collection;) “209151;”
- Chrome Broswer V98 Can not manually add cookies locally, refresh cannot be retained, and the cookie item is red
- Unable to read workspace file ‘D:\angular.json‘: Invalid JSON character: “ “ at
- JSON data format net.sf.json .JSONException: A JSONObject text must begin with ‘{‘ at character 1 of Error:(f…