Answer the question
In order to leave comments, you need to log in
How to view cookies??
How to view cookies when replying? and does it return cookies at all?
I use OkHttp, because I'm doing an android application and there should be a library without problems
OkHttpClient client = new OkHttpClient.Builder()
.cookieJar(new CookieJar() {
private final HashMap<HttpUrl, List<Cookie>> cookieStore = new HashMap<>();
@Override
public void saveFromResponse(HttpUrl url, List<Cookie> cookies) {
cookieStore.put(url, cookies);
}
@Override
public List<Cookie> loadForRequest(HttpUrl url) {
List<Cookie> cookies = cookieStore.get(url);
return cookies != null ? cookies : new ArrayList<Cookie>();
}
})
.build();
Request request = new Request.Builder()
.url("https://toster.ru")
.build();
String html = null;
Call call = client.newCall(request);
try {
Response response = call.execute();
html = response.body().string();
} catch (IOException e) {
e.printStackTrace();
}
List<Cookie> list = client.cookieJar().loadForRequest(HttpUrl.parse("toster.ru"));
System.out.println(list.size() + " Cookie");//Показывает 0
Answer the question
In order to leave comments, you need to log in
If we look at the headers that https://toster.ru/ returns, we will see the following:
HTTP/1.1 200 OK
Connection: keep-alive
Content-Encoding: gzip
Content-Type: text/html;charset=utf-8
Date: Thu, 24 Aug 2017 17:14:51 GMT
Keep-Alive: timeout=15
Public-Key-Pins: pin-sha256="klO23nT2ehFDXCfx3eHTDRESMz3asj1muO+4aIdjiuY=";pin-sha256="ATPF8U6AdEXM7aD9/PTAJldZj9jI6NWEvRGMbDJiN3g="; max-age=15552000
Server: QRATOR
Strict-Transport-Security: max-age=31536000
Transfer-Encoding: chunked
X-Powered-By: PHP/5.6.20-1+deb.sury.org~trusty+1
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question