Getting raw HTTP response headers

后端 未结 4 1584
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-08 06:30

Is there any way to get raw response http header?

The getHeaderField() method doesn\'t work for me, because server spits multiple \'Set-Cookie\' and som

4条回答
  •  长情又很酷
    2020-12-08 06:56

    Late to the party, but here's the simplest solution. Just implement CookieStore. (or use the default implementation and let it take care of adding the cookies to your subsequent calls.)

    http://docs.oracle.com/javase/7/docs/api/java/net/CookieStore.html

    Set your cookie store as the default cookie manager

    CookieManager cookieManager = new CookieManager(new MyCookieStore(), CookiePolicy.ACCEPT_ALL);
    CookieHandler.setDefault(cookieManager);
    

    And every new cookie will appear to you in add() in your CookieStore. I had the same problem with params being overwritten by having the same name "Set-Cookie" in a single request, and now I get both the cookie and the sessionId.

提交回复
热议问题