1

供您参考的代码块如下:

String hostname = "Hostname Value";
URI uri = new URI(hostname + "/solr/add/story/" + story.getId() + ".html");
final HTTPConnection con = new HTTPConnection(uri);
con.setAllowUserInteraction(false);
final HTTPResponse response = con.Get(uri.getPathAndQuery());

在这里,在访问响应时,我遇到了以下异常:

[ WARN] [com.thestreet.cms.integration.solr.SolrService] 12/02/2013 22:52:54-Unable                       
update front end search engine index with story 10446446 
java.net.ProtocolException: Bad Set-Cookie header: FV=OID-|PID-|MID-|PUC-|DATE-         
529D5595; path=/; expires=Tue, 01-Jan-2035 00:00:00 GMT; domain=.thestreet.com;,       
BRIS=C0.A8.41.91|529D55951FB74EF; path=/; expires=Tue, 01-Jan-2035 00:00:00 GMT;     
domain=.thestreet.com;, 
RGIS=-1386042773,192.168.65.145,BA42A8C0,1076F795713A21E010941898-    0-1386042773-; 
path=/; expires=Tue, 01-Jan-2035 00:00:00 GMT; domain=.thestreet.com;,     
JSESSIONID=8A8A377CF937F6184D3F4774CC6F4CBA; Version=1; Path="/"; HttpOnly 
No '=' found for token starting at position 432 
at HTTPClient.Cookie.parse(Cookie.java:243) 
at HTTPClient.CookieModule.handleCookie(CookieModule.java:454) 
at HTTPClient.CookieModule.responsePhase1Handler(CookieModule.java:403) 
at HTTPClient.HTTPResponse.handleResponse(HTTPResponse.java:724) 
at HTTPClient.HTTPResponse.getStatusCode(HTTPResponse.java:190) 
at com.thestreet.cms.integration.solr.SolrService$1.run(SolrService.java:450) 
at java.lang.Thread.run(Thread.java:722)

这似乎是由 cookie 标头中的 Httponly 位引起的,因为它不是键值对的形式。有什么方法可以在读取响应时避免 cookie 标头或 cookie 检查?请帮忙。

提前致谢。

4

1 回答 1

0

问题是您的 http 请求/响应在其标头中包含“HttpOnly”。应用服务器似乎不再支持此值。为了解决这个问题,我编写了一个解决方法,将“HttpOnly”从服务器端的响应中删除。

String header = resp.getHeader("Set-Cookie");
if (header != null && header.endsWith("HttpOnly")) {
    resp.setHeader("Set-Cookie", header.substring(0, header.length() - 8));
}

但最好的解决方案是从 http 客户端的标头中删除“HttpOnly”。

于 2020-09-15T12:45:12.407 回答