2

I am doing this request :

    OkHttpClient client = new OkHttpClient();
    MediaType mediaType = MediaType.parse("application/x-www-form-urlencoded");
    RequestBody body = RequestBody.create(mediaType, "username=George&password=toto");
    Request request = new Request.Builder()
            .url("http://localhost:8080/login")
            .post(body)
            .addHeader("content-type", "application/x-www-form-urlencoded")
            .build();
    try {
        Response response = client.newCall(request).execute();

    } catch (IOException e) {
        e.printStackTrace();
    }

But how to get the cookies that the server returned me? I just want to store it on a String variable (that's all)

Thank you in advance !

Loris.Foe
  • 21
  • 1
  • 3

1 Answers1

0

The idea here is to create or use an existing CookieJar implementation and then read the cookies from that. See this answer for more details.

mattbdean
  • 2,532
  • 5
  • 26
  • 58