我是开发人员,当Cookie包含变音字符(ä,ö,ü)时,我面临以下例外,我尝试了许多解决方案和配置而没有任何结果。
我使用Tomcat7
任何解决方案
Feb 21, 2013 6:29:16 AM org.apache.coyote.http11.AbstractHttp11Processor process
SEVERE: Error processing request
java.lang.IllegalArgumentException: Control character in cookie value or attribute.
at org.apache.tomcat.util.http.CookieSupport.isHttpSeparator(CookieSupport.java:193)
at org.apache.tomcat.util.http.Cookies.getTokenEndPosition(Cookies.java:488)
at org.apache.tomcat.util.http.Cookies.processCookieHeader(Cookies.java:291)
at org.apache.tomcat.util.http.Cookies.processCookies(Cookies.java:168)
at org.apache.tomcat.util.http.Cookies.getCookieCount(Cookies.java:106)
at org.apache.catalina.connector.CoyoteAdapter.parseSessionCookiesId(CoyoteAdapter.java:919)
at org.apache.catalina.connector.CoyoteAdapter.postParseRequest(CoyoteAdapter.java:688)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:402)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:987)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:579)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1600)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:722)
答案 0 :(得分:0)
使用UTF-8编码。
您可以全局设置:
java -Dfile.encoding=UTF-8
或在当地:
System.setProperty("file.encoding", "UTF-8");
byte inbytes[] = new byte[1024];
FileInputStream fis = new FileInputStream("the.location.of.your.cookie");
fis.read(inbytes);
另外,如果您手动编辑cookie,请不要保存Ä。而是使用UTF-8等效,
System.out.println("\u00c4");
Chars Unicode
------------------------------
Ä, ä \u00c4, \u00e4
Ö, ö \u00d6, \u00f6
Ü, ü \u00dc, \u00fc
ß \u00df
答案 1 :(得分:0)
现在我遇到了同样的问题,首先,我尝试将tomcat 7升级到tomcat 8.5.51,它可以工作,但是却提出了新的问题
java.lang.IllegalArgumentException: An invalid domain [.foo.bar.com] was specified for this cookie
因为我不需要使用cookie,所以我只排除了Nginx级别的cookie,它也可以解决此问题
proxy_set_header Cookie "";