Answer the question
In order to leave comments, you need to log in
Is it possible to replace an individual cookie in a request?
There is a store site, where the region is changed not by going to a specific URL, but by setting a specific cookie in Javascript. A sort of "protection" from robots.
Please tell me: is it possible between the first http request (where you need to get certain cookies, for example PHPSESSID) and the next one (where you need to get information about a product in a particular region) to change only 1 cookie, while leaving the rest unchanged ?
Can this be done in the standard java.net.URL or org.apache.http.client?
Or is there some alternative "lightweight" library?
Answer the question
In order to leave comments, you need to log in
The servlet receives the request, sets the cookie, and redirects to the desired page.
public class TestServlet extends HttpServlet {
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
super.doGet(req, resp);
Cookie[] cookies = req.getCookies();
for (int i = 0; cookies != null && i < cookies.length; i++) {
if ("MyCookie".equals(cookies[i].getName())) {
resp.addCookie(cookies[i]);
}
}
resp.sendRedirect("/myPage");
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question