我发现部署在tomcat上的API能够在我发送cURL请求时抓取cookie,尽管有tomcat警告。
curl -XPOST -H "Content-Type: application/json" --cookie "userId=64ad960c-bb7e-48dd-8191-4f31539bc2c2,accessToken=64ad960c-bb7e-48dd-8191-4f31539bc2c2" -d '{"message":"play porcupine tree"}' http://localhost:9090/nlu/convo
但是要删除警告,必须在tomcat配置(LegacyCookieProcessor
conf/context.xml
)
例
cat /usr/local/apache-tomcat-8.5.12/conf/context.xml
<?xml version="1.0" encoding="UTF-8"?>
<!-- The contents of this file will be loaded for each web application -->
<Context>
<WatchedResource>WEB-INF/web.xml</WatchedResource>
<WatchedResource>${catalina.base}/conf/web.xml</WatchedResource>
<!--
<CookieProcessor className="org.apache.tomcat.util.http.Rfc6265CookieProcessor" />
-->
<CookieProcessor className="org.apache.tomcat.util.http.LegacyCookieProcessor" />
</Context>
我以为会工作,但没有,是必需的。org.apache.tomcat.util.http.Rfc6265CookieProcessor
LegacyCookieProcessor
参考
https://tomcat.apache.org/tomcat-8.5-doc/config/cookie-processor.html#Legacy_Cookie_Processor_-_org.apache.tomcat.util.http.LegacyCookieProcessor
https://www.rfc-editor.org/rfc/rfc6265
LegacyCookieProcessor
对 Cookie 规范进行严格的解释。由于浏览器的各种互操作性问题,默认情况下并非所有严格行为都处于启用状态,如果需要,可以使用其他选项来进一步放松此cookie处理器的行为。