错误:java.lang.IllegalArgumentException: An invalid character [34] was present in the Cookie value

场景,在进行java后台存储cookie时,报错误如下:

错误:java.lang.IllegalArgumentException: An invalid character [34] was present in the Cookie value

出错的原因是:Cookie 的值里面包含了 “An invalid character [34]”,那 “character [34]” 是什么呢?

于是找到对应的ASCII码表:

ASCLL码表

从表中可以看出,是因为Cookie中包含了单引号。

  因此,我们可以有两种方案去解决:

  (1)去掉Cookie值里面的单引号

  (2)对 Cookie 的值进行进行编码:

String encodeCookie = URLEncoder.encode(Cookie的值 "utf-8");

    要取它里面的值的时候,再对其进行解码:

 URLDecoder.decode(encodeCookie , "utf-8")
原创文章 84 获赞 46 访问量 21万+

猜你喜欢

转载自blog.csdn.net/yyj108317/article/details/105138037
今日推荐