0

I want to create cookie which contains special char. I have tried many solutions but it remains same. It means that it automatically deletes the values after special char.

json = [{"message":"D10QAC"},{"message":"D10P;F"},{"message":"D10PAF"}]

Cookie cookie = new Cookie("cookie", json); 
cookie.setMaxAge(10000);
response.addCookie(cookie);

But when the cookie is stored is like [{"message":"D10QAC"},{"message":"D10P;

I also tried to decode this cookie by using URLEncoder.encode(json, "UTF-8") but it also have same problem.

Any help ? Thanks in advance.

rockroyal
  • 25
  • 7
  • You should provide us with the type of that json object, as well as what frameworks you are using. Where is this "Cookie" class coming from? – Johan Tidén May 25 '17 at 10:17
  • `@Johan.` I have created cookies in spring framework. And the Cookie class is from `javax.servlet.http.Cookie` – rockroyal May 25 '17 at 10:39
  • Thanks. The Cookie class takes a String as json. You should show us the code to produce that String and/or what the actual value of the string is. – Johan Tidén May 25 '17 at 11:00

1 Answers1

0

I would say this is not generally possible, as ; symbol is an escape separator character for the HTTP headers (look also on this answer: https://stackoverflow.com/a/19028585/1479414).

So probably best solution will be encode your json into base64 string and store it in cookie value.

Andremoniy
  • 34,031
  • 20
  • 135
  • 241