Y
Y
ywitodenasuby2019-03-09 12:34:23
Java
ywitodenasuby, 2019-03-09 12:34:23

How to get cookies set via JavaScript?

On the page with the authorization form, cookies are set via JavaScript and then checked on the server. Which is why you can't log in. HttpsURLConnection does not see. What to do? Fragment 1 has all the cookies, along with those that JavaScript has set. On fragment 2, those that return HttpsURLConnection. As you can see, many are missing.
5c8388f35a1cf899377679.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
Orkhan, 2019-03-09
Hasanly @azerphoenix

You can get an array of cookies and iterate over it. And for this you need to use not HttpsURLConnection, but HttpServletRequest request from the package - javax.servlet.http.HttpServletRequest;
https://stackoverflow.com/questions/22804409/get-c...

Cookie[] cookies = request.getCookies();

if (cookies != null) {
 for (Cookie cookie : cookies) {
   if (cookie.getName().equals("cookieName")) {
     //do something
     //value can be retrieved using #cookie.getValue()
    }
  }
}

If you are using Spring, then you can do it differently:
https://viralpatel.net/blogs/spring-mvc-cookie-example/
@CookieValue("foo") String fooCookie

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question