title: Android: Jsoup login - https
body: <p>How is it possible to login programmatically on to a website ?</p>
  
  <p>Example: The User type in his login data in EditText and click on the login Button. Then opens a WebView, where he is logged in.</p>
  
  <p>I tried to work with these code examples but:</p>
  
  <p><a href="https://stackoverflow.com/questions/7744075/how-to-connect-via-https-using-jsoup">How to connect via HTTPS using Jsoup?</a> - i got Errors</p>
  
  <p><a href="https://stackoverflow.com/questions/30268309/how-to-log-in-to-an-https-website-with-jsoup">How to log in to an HTTPS website with Jsoup?</a> - i didnt got Errors but i cant login</p>
  
  <p><a href="https://stackoverflow.com/questions/16058067/jsoup-https-connecting">Jsoup HTTPS connecting</a> - it dont work i got Errors</p>
  
  <p>After i used this, i tried this</p>
  
  <pre><code>class JsoupAsyncIserv extends AsyncTask&lt;Void, Void, Void&gt; {
  
      @Override
      protected void onPreExecute() {
          super.onPreExecute();
      }
  
      @Override
      protected Void doInBackground(Void... params) {
          //HTML Parsen
          try {
  
  
              Connection.Response login = Jsoup.connect("https://lmg-nhs.de/idesk")
                      .data("login_act", "MyUsername")
                      .data("login_pwd", "MyPW")
                      .method(Connection.Method.POST)
                      .execute();
  
              Document document = Jsoup.connect("https://lmg-nhs.de/idesk")
                      .cookies(login.cookies())
                      .get();
          } catch (IOException e) {
              e.printStackTrace();
          }
          return null;
      }
  
      @Override
      protected void onPostExecute(Void result) {
  
  
      }
  }
  </code></pre>
  
  <p>It works, but i cant login.</p>
  
  <pre><code>private class IServAsyncTask extends AsyncTask&lt;Void, Void, Void&gt;{
  
          private String resp;
          protected String doInBackground(String... params) {
              Connection.Response res = null;
              try {
                  res = Jsoup.connect("https://lmg-nhs.de")
                          .data("login_act", "myUsername")
                          .data("login_pwd", "myPW")
                          .data("submit", "Anmelden")
                          .method(Connection.Method.POST)
                          .execute();
  
              } catch (IOException e) {
                  e.printStackTrace();
              }
  
              try {
                  Document doc = res.parse();
              } catch (IOException e) {
                  e.printStackTrace();
              }
              String sessionId = res.cookie("PHPSESSID");
  
              try {
                  Document doc2 = Jsoup.connect("https://lmg-nhs.de")
                          .cookie("PHPSESSID", sessionId)
                          .get();
              } catch (IOException e) {
                  e.printStackTrace();
  
              }
  
              return resp;
          }
  
          @Override
          protected Void doInBackground(Void... voids) {
              return null;
          }
      }
  </code></pre>
  
  <p>If you can, try to explain it at an or my example, because beginners (like me) can easier learn it this way.</p>