Sending Cookie info in HttpRequest

前端 未结 5 1506
抹茶落季
抹茶落季 2020-12-10 20:11

I want to call a web service that requires an authentication cookie.

I have the cookie name and value. but I don\'t know how to inject the cookie in the request.

5条回答
  •  醉酒成梦
    2020-12-10 20:48

    There is no method for adding a cookie to an HttpRequest, but you can set a header or parameter.

    Cookies are added to the HttpServletResponse like this:

    HttpServletResponse response; //initialized or passed in
    Cookie cookie = new Cookie("myname", "myvalue");
    response.addCookie(cookie);
    

提交回复
热议问题