title: how to maintain variable cookies and sessions with jsoup?
body: <pre><code>public boolean isGood(String path)
  {
      if (p != path)
      {
          good = false;
      }
  
      if (good)
      {
          try 
          {
              Connection connection = Jsoup.connect(path);
              Map&lt;String, String&gt; cookys = Jsoup.connect(path).response().cookies();
  
              if (cookys != cookies)
                  cookies = cookys;
  
              for (Entry&lt;String, String&gt; cookie : cookies.entrySet()) 
              {
                  connection.cookie(cookie.getKey(), cookie.getValue());
              }
  
              Doc = connection.get();
              good = true;
          }
          catch (Exception e) 
          {
              rstring = e.getMessage().toString();
              good = false;
          }
      }
      else
      {
          try
          {
              Response response = Jsoup.connect(path).execute();
              cookies = response.cookies();
              Doc = response.parse();
              good = true;
          }
          catch (Exception e) 
          {
              rstring = e.getMessage().toString();
              good = false;
          } 
      }       
      return good;
  }
  </code></pre>
  
  <p>This method is not right. What I'm trying to figure out is a way to without know what cookies will exist, be able to handle cookie changes as well as maintain sessions.</p>
  
  <p>I'm writing an app for my simple machines forum, and it changes its cookie config as you click around for some custom behavior. </p>
  
  <p>But if the app does well for my site, I was going to publish a version for others to use for other forums. </p>
  
  <p>I know I'm heading in the right direction, but the logic is kind of kicking my butt.</p>
  
  <p>Any advice would be greatly appreciated.</p>