Answer the question
In order to leave comments, you need to log in
How to correctly get Cookies in Java?
Hello! I have a code that correctly receives cookies from the site and saves it in a file, I run it from the development environment:
String url = "https://www.avito.ru";
Map<String, String> cookies = Jsoup.connect(url).execute().cookies();
ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(file));
out.writeObject(cookies);
System.out.println("Get cookies from: " + url + " and write into: " + file.getName());
System.out.println(cookies);
out.close();
try {
Map <String, String> cookies = Jsoup.connect(url)
.execute()
.cookies();
cookieHandler.setAvitoCookies(cookies);
System.out.println("> AVITO COOKIE:" + cookies);
} catch (IOException e) {
e.printStackTrace();
}
org.jsoup.HttpStatusException: HTTP error fetching URL. Status=403, URL=https://www.avito.ru
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question