code: private void loadRequestCookies() throws IOException {
      CookieHandler cookieHandler = CookieHandler.getDefault();
      if (cookieHandler != null) {
        try {
          URI uri = getURL().toURI();
          Map<String, List<String>> cookieHeaders =
              cookieHandler.get(uri, getHeaderFieldsDoNotForceResponse());
          for (Map.Entry<String, List<String>> entry : cookieHeaders.entrySet()) {
            String key = entry.getKey();
            if (("Cookie".equalsIgnoreCase(key)
                || "Cookie2".equalsIgnoreCase(key))
                && !entry.getValue().isEmpty()) {
              List<String> cookies = entry.getValue();
              StringBuilder sb = new StringBuilder();
              for (int i = 0, size = cookies.size(); i < size; i++) {
                if (i > 0) {
                  sb.append("; ");
                }
                sb.append(cookies.get(i));
              }
              setHeader(key, sb.toString());
            }
          }
        } catch (URISyntaxException e) {
          throw new IOException(e);
        }
      }
    }
docs: Add any cookies for this URI to the request headers.