title: How do i receive the cookies sent in response by the server using OkHttp?
body: <p>I have another one for logging in.  So this is how I see it, every time I try running this code, it asks me to authenticate.</p>
  
  <p>So this is how it works I suppose, I basically have to run the login code first, store the cookies sent in response by the server and use it for subsequent operations, like for example making changes in the servers database.
  I am able to make these changes via postman.</p>
  
  <p><strong>so how do i receive the cookies sent in response by the server?</strong></p>
  
  <pre><code>OkHttpClient client = new OkHttpClient();
  
  MediaType mediaType = MediaType.parse("multipart/form-data; boundary=----
  WebKitFormBoundary7MA4YWxkTrZu0gW");
  RequestBody body = RequestBody.create(mediaType, "------
  WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; 
  name=\"username\"\r\n\r\nadmin\r\n------
  WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; 
  name=\"password\"\r\n\r\nadmin\r\n------
  WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; 
  name=\"this_is_the_login_form\"\r\n\r\n1\r\n------
  WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; 
  name=\"post_data\"\r\n\r\n\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW--");
  Request request = new Request.Builder()
    .url("http://localhost:8081/iclock/accounts/login/?
  next=/iclock/data/iclock/")
    .post(body)
    .addHeader("content-type", "multipart/form-data; boundary=----
  WebKitFormBoundary7MA4YWxkTrZu0gW")
    .addHeader("Cache-Control", "no-cache")
    .addHeader("Postman-Token", "86439550-93f7-6d60-1aab-7d289c137b0d")
    .build();
  
  Response response = client.newCall(request).execute();
  </code></pre>